summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2022-01-24 17:54:06 +0100
committerChristian Schneider2022-01-24 17:54:06 +0100
commite867407ae8b86b3170f0f103607d54a0fb7c616e (patch)
tree3d14a876dcb5bdf6eae3eed09292ccef3e8ffa6d
parentffc9ba95e50e3e3c4fdd6f78f0fa43accf5038f2 (diff)
downloaditools-e867407ae8b86b3170f0f103607d54a0fb7c616e.tar.gz
itools-e867407ae8b86b3170f0f103607d54a0fb7c616e.tar.bz2
itools-e867407ae8b86b3170f0f103607d54a0fb7c616e.zip
Fix PHP 8.1 warning when URL given to U() is invalid
-rw-r--r--it_html.class3
-rw-r--r--test/U_tests.json6
2 files changed, 9 insertions, 0 deletions
diff --git a/it_html.class b/it_html.class
index 70994e7..d65b101 100644
--- a/it_html.class
+++ b/it_html.class
@@ -502,7 +502,10 @@ static function U(...$args)
$base = preg_replace('|\0|', '', $base); # kill null chars
if (!($u = @parse_url($base)))
+ {
+ $u = [];
list($u['path'], $u['query']) = explode("?", $base, 2);
+ }
$u['host'] = preg_match('/[^-_.0-9a-z]/i', $u['host']) && function_exists('idn_to_ascii') && ($idnahost = idn_to_ascii($GLOBALS['it_html']->p['charset'] == "iso-8859-1" ? utf8_encode($u['host']) : $u['host'])) ? $idnahost : $u['host']; # Punycode hostname to include into webpage
$u['host'] = preg_replace_callback('/[^-_.0-9a-z\x80-\xff]/i', function($m) { return rawurlencode($m[0]); }, $u['host']); # Encode garbage chars in host
diff --git a/test/U_tests.json b/test/U_tests.json
index 0025565..83a6771 100644
--- a/test/U_tests.json
+++ b/test/U_tests.json
@@ -219,5 +219,11 @@
"args": ["a:b:c:d:javascript:alert('fail');"],
"exp": "alert(%27fail%27)%3B",
"name": "U() remove multiple schemes from path"
+ },
+
+ {
+ "args": ["//Oeffnungszeiten:8.30-17.00/"],
+ "exp": "//Oeffnungszeiten:8.30-17.00/",
+ "name": "U() with invalid URL"
}
]