summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_html.class2
-rw-r--r--it_url.class13
-rwxr-xr-xtests/it_html.t6
3 files changed, 20 insertions, 1 deletions
diff --git a/it_html.class b/it_html.class
index ea8a159..9ffd4e3 100644
--- a/it_html.class
+++ b/it_html.class
@@ -542,7 +542,7 @@ static function U(/* ... */)
if (!($u = @parse_url($base)))
list($u['path'], $u['query']) = explode("?", $base, 2);
- parse_str($u['query'], $u['params']);
+ $u['params'] = it_url::parse_str($u['query']);
$u['host'] = preg_match('/[^-_.0-9a-z]/i', $u['host']) && function_exists('idn_to_ascii') && ($idnahost = idn_to_ascii($GLOBALS['it_html']->p['charset'] == "iso-8859-1" ? utf8_encode($u['host']) : $u['host'])) ? $idnahost : $u['host']; # Punycode hostname to include into webpage
$u['host'] = preg_replace_callback('/[^-_.0-9a-z\x80-\xff]/i', function($m) { return rawurlencode($m[0]); }, $u['host']); # Encode garbage chars in host
diff --git a/it_url.class b/it_url.class
index b7ea7d7..5563b5e 100644
--- a/it_url.class
+++ b/it_url.class
@@ -824,6 +824,19 @@ static function _params($params, $keys = null)
return $result;
}
+
+static function parse_str($query)
+{
+ foreach (explode('&', $query, 2) as $arg)
+ {
+ list($key, $value) = explode("=", $arg, 2);
+ $result[urldecode($key)] = urldecode($value);
+ }
+
+ return (array)$result;
+}
+
+
/**
* Convert url into array with base url in $result[0] and GET params
*/
diff --git a/tests/it_html.t b/tests/it_html.t
index 538a350..2291c54 100755
--- a/tests/it_html.t
+++ b/tests/it_html.t
@@ -196,6 +196,12 @@ is(
);
is(
+ U("/foo.html?bar.qux=a.b", array('c.d' => "e.f", 'g h' => "i j")),
+ '/foo.html?bar.qux=a.b&c.d=e.f&g+h=i+j',
+ 'U() dots and spaces in arg names are preserved'
+);
+
+is(
U("/foo.html?bar=qux#frag=frog", array('baz' => "gna")),
'/foo.html?bar=qux&baz=gna#frag=frog',
'U() fragment after params'