summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2017-11-28 15:06:41 +0100
committerNathan Gass2017-11-28 15:07:38 +0100
commitfdafbf02b626b5d0cf47ca982bbf5cf64e27084f (patch)
tree4da8e28f44d785e26ce7fae31260bcd8f2473283
parent7a065544ad3b43c891d72ea5ae400a143f38f070 (diff)
downloaditools-fdafbf02b626b5d0cf47ca982bbf5cf64e27084f.tar.gz
itools-fdafbf02b626b5d0cf47ca982bbf5cf64e27084f.tar.bz2
itools-fdafbf02b626b5d0cf47ca982bbf5cf64e27084f.zip
simplify % code, test % at end and with digits
-rw-r--r--it_html.class5
-rw-r--r--tests/U_tests.json4
2 files changed, 3 insertions, 6 deletions
diff --git a/it_html.class b/it_html.class
index 02f3f2a..c7105b7 100644
--- a/it_html.class
+++ b/it_html.class
@@ -556,10 +556,7 @@ static function U(/* ... */)
$schemepart = $hostpart ? ($u['scheme'] ? $u['scheme'] . ":" : "") . "//$hostpart" : ($u['scheme'] == "mailto" ? $u['scheme'] . ":" : "");
# hack: encode % if not followed by two hex digits
- $parts = preg_split('/%([^%]{0,2})/', $u['path'], -1, PREG_SPLIT_DELIM_CAPTURE);
- for ($i = 1; $i < count($parts); $i+=2)
- $parts[$i] = (preg_match('/[0-9a-f][0-9a-f]/i', $parts[$i]) ? "%" : "%25") . $parts[$i];
- $path = join("", $parts);
+ $path = preg_replace('/%(?![0-9a-f]{2})/i', '%25', $u['path']);
# if params replace url parameters that are present in base, replace them but keep their order
foreach ($u['params'] as $key => $dummy)
diff --git a/tests/U_tests.json b/tests/U_tests.json
index bf8d129..a8b5688 100644
--- a/tests/U_tests.json
+++ b/tests/U_tests.json
@@ -37,8 +37,8 @@
},
{
- "args": ["%% %1%x %1x%x1%xx%11%ff%FF"],
- "exp": "%25%25%20%251%25x%20%251x%25x1%25xx%11%ff%FF",
+ "args": ["%% %1%x %1x%x1%xx%11%ff%FF%0f%0F %"],
+ "exp": "%25%25%20%251%25x%20%251x%25x1%25xx%11%ff%FF%0f%0F%20%25",
"name": "U() quoting of % if not followed by 2 hex digits"
},