diff options
-rw-r--r-- | it_url.class | 7 | ||||
-rw-r--r-- | tests/U_tests.json | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class index 3a8cc41..30a1e41 100644 --- a/it_url.class +++ b/it_url.class @@ -707,7 +707,7 @@ static function params($params, $keys = null) return join("&", it_url::_params($params, $keys)); } -static function _params($params, $keys = null) +static function _params($params, $keys = null, $finalize = true) { $result = array(); @@ -718,7 +718,7 @@ static function _params($params, $keys = null) { if (is_array($params[$key])) { - foreach (it_url::_params($params[$key]) as $value) + foreach (it_url::_params($params[$key], null, false) as $value) { if (strlen($value)) $result[] = it::replace(array('^([^=\[]*)' => $key . '[$1]'), $value); @@ -728,6 +728,9 @@ static function _params($params, $keys = null) $result[] = urlencode($key) . "=" . it_url::encode($params[$key]); } + if ($finalize) + $result = preg_replace(['#\[#', '#\]#'], ['%5B', '%5D'], $result); + return $result; } diff --git a/tests/U_tests.json b/tests/U_tests.json index 2d868e3..591fdc9 100644 --- a/tests/U_tests.json +++ b/tests/U_tests.json @@ -85,7 +85,7 @@ { "args": ["/foo.html", {"bar": {"gna": 42, "qux": {"quux": "<Zürich>", "gnöp": "fasel"}}}], - "exp": "/foo.html?bar[gna]=42&bar[qux][quux]=%3CZ%C3%BCrich%3E&bar[qux][gn%C3%B6p]=fasel", + "exp": "/foo.html?bar%5Bgna%5D=42&bar%5Bqux%5D%5Bquux%5D=%3CZ%C3%BCrich%3E&bar%5Bqux%5D%5Bgn%C3%B6p%5D=fasel", "name": "U() with nested arrays" }, |