Kit-UrlParser
Kit-UrlParser copied to clipboard
Invalid URI, if array in query params
I have a problem with an array in query params.
Example:
$url = 'https://example.localhost/?fields[articles]=title';
$uri = new Uri($url, UriParser::MODE_UTF8);
Error:
InvalidArgumentException
/Kit-UrlParser/src/Uri.php:54
I have no influence on the generation of the Urls, because they come from another extension. Have you got a solution for this problem?
Strictly speaking, the problem is that [ and ] are not valid characters in the query part of the URI according to rfc3986 and this library was originally created with the intention of validating URLs strictly according to that RFC.
The extension you are using really ought to build URLs using logic similar to http_build_query(), so that the [] characters would get encoded properly like fields%5Barticles%5D=title.
But, I do realize that unfortunately a lot of places do not really conform to the spec very strictly so I might have to think about adding some kind of lenient parsing mode that would allow more characters than what the spec defines.