summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2009-11-17 16:49:02 +0000
committerUrban Müller2009-11-17 16:49:02 +0000
commit65ba5016508204dc5b8dce47bc7a7e88d803bbd1 (patch)
treee4a41896afe4c28d3cbb7fd1f848eda3bcfefc39
parentf6dee426b69cf8225c2a2511bb73a8977866137c (diff)
downloaditools-65ba5016508204dc5b8dce47bc7a7e88d803bbd1.tar.gz
itools-65ba5016508204dc5b8dce47bc7a7e88d803bbd1.tar.bz2
itools-65ba5016508204dc5b8dce47bc7a7e88d803bbd1.zip
dont urlencode IDN host parts in U()
-rw-r--r--it_html.class26
1 files 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" : "");
}