diff options
-rw-r--r-- | it.class | 21 | ||||
-rwxr-xr-x | test/it.t | 5 |
2 files changed, 23 insertions, 3 deletions
@@ -1335,7 +1335,7 @@ static function params2utf8() foreach (['PHP_SELF', 'SCRIPT_NAME', 'SCRIPT_URL', 'SCRIPT_URI', 'HTTP_USER_AGENT'] as $var) $_SERVER[$var] = it::any2utf8($_SERVER[$var]); - $urlfix = function($m) { return urlencode(it::any2utf8(urldecode($m[0]))); }; + $urlfix = function($m) { return urlencode(it::any2utf8(urldecode($m[0]))); }; # NOPHPLINT foreach (['QUERY_STRING', 'REQUEST_URI', 'HTTP_REFERER'] as $var) { $_SERVER[$var.'_RAW'] = $_SERVER[$var]; @@ -1343,7 +1343,7 @@ static function params2utf8() if (strpos($_SERVER[$var], '%') !== false) { - if (grapheme_strlen(urldecode($_SERVER[$var])) === null) # handle latin (double encodes correct utf8) + if (grapheme_strlen(urldecode($_SERVER[$var])) === null) # NOPHPLINT handle latin (double encodes correct utf8) $_SERVER[$var] = preg_replace_callback('/%[89A-F][A-Z0-9]/i', $urlfix, $_SERVER[$var]); while (preg_match('/%C3%8[23]%C2%[89ab][0-9a-f]/i', $_SERVER[$var]) && $iterations++ < 3) # handle doubly encoded utf8, UTF8SAFE $_SERVER[$var] = preg_replace_callback('/%C3%8[23]%C2%[89ab][0-9a-f]/i', $urlfix, $_SERVER[$var]); @@ -1366,4 +1366,21 @@ static function setcookie($name, $value, $p = []) : @setcookie($name, $value, $p); } +static function urldecode($str) +{ + return it::any2utf8(urldecode($str)); # NOPHPLINT +} + +static function parse_str($str) # note different usage +{ + parse_str($str, $request); # NOPHPLINT + + return it::any2utf8($request); +} + +static function request_body() +{ + return it::any2utf8(it::file_get_contents('php://input')); +} + } @@ -539,7 +539,7 @@ function requesturi($teststring, $expect) { $_SERVER['REQUEST_URI'] = urlencode($teststring); it::params2utf8(); - is(urldecode($_SERVER['REQUEST_URI']), $expect, "parms2utf8('$expect')"); + is(urldecode($_SERVER['REQUEST_URI']), $expect, "parms2utf8('$expect')"); # NOPHPLINT } _getopt(["val"], ['foo' => "val"]); @@ -567,3 +567,6 @@ function _getopt($in, $expect) is($opts, ['args' => $expect['args'] ?? []] + $expect); } + +is(it::urldecode("a%61%E4"), "aaä"); +is(it::parse_str("%E4[%E4][%E4]=%E4"), ['ä' => ['ä' => ['ä' => 'ä']]]); |