From 65ba5016508204dc5b8dce47bc7a7e88d803bbd1 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 17 Nov 2009 16:49:02 +0000 Subject: dont urlencode IDN host parts in U() --- it_html.class | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/it_html.class b/it_html.class index 15442c3..5569309 100644 --- a/it_html.class +++ b/it_html.class @@ -442,20 +442,32 @@ function u(/* ... */) if (!isset($base)) $base = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']); - $base = preg_replace(array('|\0|', '/\\\\/'), array('', '/'), $base); + $base = preg_replace(array('|\0|', '/\\\\/'), array('', '/'), $base); # kill null chars, turn \ to / + + $u = parse_url($base); + + # handle scheme, user, password, host + $hostpart = + ($u['user'] ? $u['user'] . ($u['pass'] ? ":" . $u['pass'] : "") . "@" : "") . + ($u['host'] ? $u['host'] : "") . + ($u['port'] ? ":" . intval($u['port']) : ""); + + $schemepart = $hostpart ? ($u['scheme'] ? $u['scheme'] . ":" : "") . "//$hostpart" : ""; + + $path = $u['path'] . ($u['query'] ? "?" . $u['query'] : "") . ($u['anchor'] ? "#" . $u['anchor'] : ""); # hack: encode % if not followed by two hex digits - $parts = preg_split('/%([^%]{0,2})/', $base, -1, PREG_SPLIT_DELIM_CAPTURE); + $parts = preg_split('/%([^%]{0,2})/', $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]; - $base = join("", $parts); + $path = join("", $parts); - $base = preg_replace('|[^-\w.+!*(),:?@&=/~$%]|e', 'urlencode(stripslashes("$0"))', $base); # Single quotes are escaped with slash by preg_replace, remove it for urlencode - $base = preg_replace('|^(\w+:)?//[^/]*$|', '$0/', $base); # Add slash if absolute url without a path, e.g. http://gna.ch + $path = preg_replace('|[^-\w.+!*(),:?@&=/~$%]|e', 'urlencode(stripslashes("$0"))', $path); # Single quotes are escaped with slash by preg_replace, remove it for urlencode + $path = preg_replace('|^(\w+:)?//[^/]*$|', '$0/', $path); # Add slash if absolute url without a path, e.g. http://gna.ch $queryparams = it_url::params($params); - $separator = strpos($base, "?") === false ? "?" : "&"; + $separator = strpos($path, "?") === false ? "?" : "&"; - return $base . ($queryparams ? "$separator$queryparams" : ""); + return $schemepart . $path . ($queryparams ? "$separator$queryparams" : ""); } -- cgit v1.2.3