From c4940785503063b799175f0158e093f969c7b022 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 19 Apr 2019 20:08:53 +1000 Subject: [PATCH] Closes pull request #22 and fixes #18 - preg_replace_callback changes --- lib/ds_ldap.php | 4 ++-- lib/functions.php | 32 +++++++++++++++++--------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/ds_ldap.php b/lib/ds_ldap.php index 554f9de..1b1a19e 100644 --- a/lib/ds_ldap.php +++ b/lib/ds_ldap.php @@ -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); } } diff --git a/lib/functions.php b/lib/functions.php index 983e5cf..3333286 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -69,7 +69,7 @@ spl_autoload_register(function ($className) { /** * Strips all slashes from the specified array in place (pass by ref). * @param Array The array to strip slashes from, typically one of - * $_GET, $_POST, or $_COOKIE. + * $_GET, $_POST, or $_COOKIE. */ function array_stripslashes(&$array) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) @@ -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 \. */ -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( - "/\\\([0-9A-Fa-f]{2})/", - function ( $matches) { - return chr( hexdec( $matches[1] ) ); - }, - $value - ); - } - return ( $result ); +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( + "/\\\([0-9A-Fa-f]{2})/", + function ($matches) { + return chr(hexdec($matches[1])); + }, + $value + ); + } + + return $result; } /**