From c2c9e1d042b8eea785afdfa055d88a65e46ca2f8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2019 12:15:29 +0200 Subject: [PATCH 1/3] Fix warning --- htdocs/install/inc.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index eab86b07136..54a718ef1fc 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -253,27 +253,6 @@ foreach ($handlers as $handler) if (empty($conf->loghandlers[$handler])) $conf->loghandlers[$handler]=$loghandlerinstance; } -// Removed magic_quotes -if (function_exists('get_magic_quotes_gpc')) // magic_quotes_* removed in PHP 5.4 -{ - if (get_magic_quotes_gpc()) - { - // Forcing parameter setting magic_quotes_gpc and cleaning parameters - // (Otherwise he would have for each position, condition - // Reading stripslashes variable according to state get_magic_quotes_gpc). - // Off mode (recommended, you just do $db->escape when an insert / update. - function stripslashes_deep($value) - { - return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value)); - } - $_GET = array_map('stripslashes_deep', $_GET); - $_POST = array_map('stripslashes_deep', $_POST); - $_COOKIE = array_map('stripslashes_deep', $_COOKIE); - $_REQUEST = array_map('stripslashes_deep', $_REQUEST); - @set_magic_quotes_runtime(0); - } -} - // Defini objet langs $langs = new Translate('..', $conf); if (GETPOST('lang', 'aZ09')) $langs->setDefaultLang(GETPOST('lang', 'aZ09')); From 36c936357cb15127e1e6e419f2e8f1c95d246d9e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2019 12:25:24 +0200 Subject: [PATCH 2/3] Add phpunit testDolStringIsGoodIso --- htdocs/core/lib/functions.lib.php | 2 +- test/phpunit/FunctionsLibTest.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 625cbbee4b7..30267a57ad5 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5635,7 +5635,7 @@ function dol_string_is_good_iso($s) $ok=1; for($scursor=0;$scursor<$len;$scursor++) { - $ordchar=ord($s{$scursor}); + $ordchar=ord($s[$scursor]); //print $scursor.'-'.$ordchar.'
'; if ($ordchar < 32 && $ordchar != 13 && $ordchar != 10) { $ok=0; break; } if ($ordchar > 126 && $ordchar < 160) { $ok=0; break; } diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 5b2b65c9e50..2a7734716eb 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -1260,4 +1260,25 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase return true; } + + /** + * testDolStringIsGoodIso + * + * @return boolean + */ + public function testDolStringIsGoodIso() + { + global $conf, $langs; + + $chaine='This is an ISO string'; + $result = dol_string_is_good_iso($chaine); + $this->assertEquals($result, 1); + + $chaine='This is a not ISO string '.chr(0); + $result = dol_string_is_good_iso($chaine); + $this->assertEquals($result, 0); + + return true; + } + } From 22719b90b6524561424728d2e98df2f0cbd93e1f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2019 12:31:15 +0200 Subject: [PATCH 3/3] Fix remove warning --- htdocs/core/lib/json.lib.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 4a8f61915b5..423607fb819 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -119,7 +119,7 @@ function _val($val) */ for ($c = 0; $c < $strlen_var; ++$c) { - $ord_var_c = ord($val{$c}); + $ord_var_c = ord($val[$c]); switch (true) { case $ord_var_c == 0x08: @@ -142,18 +142,18 @@ function _val($val) case $ord_var_c == 0x2F: case $ord_var_c == 0x5C: // double quote, slash, slosh - $ascii .= '\\'.$val{$c}; + $ascii .= '\\'.$val[$c]; break; case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): // characters U-00000000 - U-0000007F (same as ASCII) - $ascii .= $val{$c}; + $ascii .= $val[$c]; break; case (($ord_var_c & 0xE0) == 0xC0): // characters U-00000080 - U-000007FF, mask 110XXXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($val{$c + 1})); + $char = pack('C*', $ord_var_c, ord($val[$c + 1])); $c += 1; $utf16 = utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -162,7 +162,7 @@ function _val($val) case (($ord_var_c & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2})); + $char = pack('C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2])); $c += 2; $utf16 = utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -171,7 +171,7 @@ function _val($val) case (($ord_var_c & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3})); + $char = pack('C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3])); $c += 3; $utf16 = utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -180,7 +180,7 @@ function _val($val) case (($ord_var_c & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4})); + $char = pack('C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3]), ord($val[$c + 4])); $c += 4; $utf16 = utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -189,7 +189,7 @@ function _val($val) case (($ord_var_c & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}), ord($val{$c + 5})); + $char = pack('C*', $ord_var_c, ord($val[$c + 1]), ord($val[$c + 2]), ord($val[$c + 3]), ord($val[$c + 4]), ord($val[$c + 5])); $c += 5; $utf16 = utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16));