From cb55bfaf566ef14c41024c5441b8c2425a212578 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 25 Oct 2022 15:51:10 +0200 Subject: be utf8 safe --- it_url.class | 11 +++++------ test/it_url.t | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/it_url.class b/it_url.class index 6058346..cc5f816 100644 --- a/it_url.class +++ b/it_url.class @@ -613,7 +613,7 @@ static function get_cache($p = array()) if ($data = $url->_get($p + ['checkonly' => true, 'filemtime' => EDC('nocache') ? null : $filemtime])) # => true means not modified (no new data fetched) { $success = true; - $newfile = it_url::_atomicwrite($path, $p['assoc'] ? serialize($data) : $data); + $isnewfile = it_url::_atomicwrite($path, $p['assoc'] ? serialize($data) : $data); if ($p['returnheaders']) it::file_put_contents("$path.headers", 'headers, true) . ";\n"); } @@ -652,7 +652,7 @@ static function get_cache($p = array()) $srcpath = $path; $path .= substr(md5(serialize($p['preprocess'])), 0, 2); - if ($filemtime = $newfile ? true : it_url::_expired($path, $p['maxage'])) # Outdated(non-zero int) or non-existant(true)? + if ($filemtime = $isnewfile ? true : it_url::_expired($path, $p['maxage'])) # Outdated(non-zero int) or non-existant(true)? { if ($lock = !$p['lock'] ?: it_url::_lock($path)) { @@ -696,7 +696,7 @@ static function get_cache($p = array()) } if (EDC('getcachelog')) - it::log('debug', 'getcachelog', $p['id'], $p['url'], $newfile && is_string($data) ? "fetched=" . mb_substr($data, 0, 500) : ""); + it::log('debug', 'getcachelog', $p['id'], $p['url'], !$isnewfile ? "" : "fetched=" . mb_substr(is_string($data) ? $data : "(assoc)", 0, 400)); ### EDC('getcache', $success, $path); # too verbose return $success ? ($p['returnheaders'] ? array($path, $headers) : $path) : false; @@ -934,7 +934,7 @@ static function parse_str($query) foreach (explode('&', $query) as $arg) { list($key, $value) = explode('=', $arg, 2); - $result[urldecode($key)] = urldecode($value); + $result[it::urldecode($key)] = it::urldecode($value); } return (array)$result; @@ -947,8 +947,7 @@ static function parse_str($query) static function parse($url) { list($path, $query) = explode("?", $url, 2); - parse_str((string)$query, $params); - return (array)$path + (array)$params; + return (array)$path + (array)it::parse_str((string)$query); } } diff --git a/test/it_url.t b/test/it_url.t index 360b971..d2bb653 100755 --- a/test/it_url.t +++ b/test/it_url.t @@ -340,3 +340,4 @@ handle_server( is(it_url::parse("/foo"), ["/foo"], "it_url::parse path only"); is(it_url::parse("/foo?"), ["/foo"], "it_url::parse empty parameter"); is(it_url::parse("/foo?bar=baz&qux=quux"), ["/foo", 'bar' => "baz", 'qux' => "quux"], "it_url::parse parameters"); +is(it_url::parse("/foo?b%E4r=b%E4z"), ["/foo", 'bär' => "bäz"]); -- cgit v1.2.3