Closes pull request #22 and fixes #18 - preg_replace_callback changes

This commit is contained in:
Deon George 2019-04-19 20:08:53 +10:00
parent 73b7795bc0
commit c494078550
2 changed files with 19 additions and 17 deletions

View File

@ -1117,12 +1117,12 @@ class ldap extends DS {
if (is_array($dn)) {
$a = array();
foreach ($dn as $key => $rdn) {
$a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return "''.chr(hexdec('${m[1]}')).''"; }, $rdn);
$a[$key] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return chr(hexdec('${m[1]}')); }, $rdn);
}
return $a;
} else {
return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return "''.chr(hexdec('${m[1]}')).''"; }, $dn);
return preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function($m) { return chr(hexdec('${m[1]}')); }, $dn);
}
}

View File

@ -2504,21 +2504,23 @@ function draw_chooser_link($form,$element,$include_choose_text=true,$rdn='none')
* ldap_explode_dn turns unprintable chars (in the ASCII sense, UTF8
* encoded) into \<hexcode>.
*/
function ldap_explode_dn_patch( $dn, $with_attrib ) {
$result = ldap_explode_dn( $dn, $with_attrib );
if (! $result ) return null;
function ldap_explode_dn_patch($dn,$with_attrib) {
$result = ldap_explode_dn($dn,$with_attrib);
if (! $result)
return null;
# translate hex code into ascii again
foreach ( $result as $key => $value ) {
$result[ $key ] = preg_replace_callback(
foreach ($result as $key => $value) {
$result[$key] = preg_replace_callback(
"/\\\([0-9A-Fa-f]{2})/",
function ( $matches) {
return chr( hexdec( $matches[1] ) );
function ($matches) {
return chr(hexdec($matches[1]));
},
$value
);
}
return ( $result );
return $result;
}
/**