From 80157030ad338d7a207b163bb9c8e0716d9068b3 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Tue, 28 Nov 2017 16:27:52 +0100 Subject: add more tests with fixes --- it_html.class | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'it_html.class') diff --git a/it_html.class b/it_html.class index c7105b7..c75f05e 100644 --- a/it_html.class +++ b/it_html.class @@ -538,7 +538,7 @@ static function U(/* ... */) if (!isset($base)) $base = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']); - $base = preg_replace(array('|\0|', '/\\\\/'), array('', '/'), $base); # kill null chars, turn \ to / + $base = preg_replace('|\0|', '', $base); # kill null chars if (!($u = @parse_url($base))) list($u['path'], $u['query']) = explode("?", $base, 2); @@ -555,20 +555,26 @@ static function U(/* ... */) $schemepart = $hostpart ? ($u['scheme'] ? $u['scheme'] . ":" : "") . "//$hostpart" : ($u['scheme'] == "mailto" ? $u['scheme'] . ":" : ""); - # hack: encode % if not followed by two hex digits - $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) if (isset($params[$key])) $u['params'][$key] = $params[$key]; - $path = preg_replace_callback('|[^-a-z0-9_.+!*(),:?@&=/~$%#]|i', function($m) { return rawurlencode($m[0]); }, $path); - $path = preg_replace('|^([a-z0-9_]+:)?//[^/]*$|', '$0/', $path); # Add slash if absolute url without a path, e.g. http://gna.ch + $u['path'] = preg_replace('|\\\\|', '/', $u['path']); # turn \ to / + foreach (['path', 'fragment'] as $key) + $u[$key] = preg_replace_callback( + '/[^-a-z0-9_.+!*(),:?@&=\/~$%#]|%(?![0-9a-f]{2})/i', + function($m) { return rawurlencode($m[0]); }, + $u[$key] + ); + + if (!$u['path'] && $hostpart) + $u['path'] = '/'; + $queryparams = it_url::params($u['params'] + $params); - $separator = strpos($path, "?") === false ? "?" : "&"; - return $schemepart . $path . ($queryparams ? "$separator$queryparams" : "") . ($u['fragment'] ? "#" . $u['fragment'] : "");; + return $schemepart . $u['path'] . ($queryparams ? "?" . $queryparams : "") . ($u['fragment'] ? "#" . $u['fragment'] : "");; } -- cgit v1.2.3