summaryrefslogtreecommitdiff
path: root/it_html.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_html.class')
-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" : "");
}