summaryrefslogtreecommitdiff
path: root/it_html.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_html.class')
-rw-r--r--it_html.class20
1 files changed, 13 insertions, 7 deletions
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'] : "");;
}