DescriptionThe problem is that the URL object doesn't distinguish between no query string and an empty query string, e.g:
new URL("http://foobar").search == new URL("http://foobar?").search == ""
Hence filters that expect a "?" to be given don't match anymore if there is an empty query string. First I considered handling this particular case, writing following code:
function stringifyURL(url)
{
let protocol = url.protocol;
if (protocol != "http:" && protocol != "https:")
return url.href;
let host = getDecodedHostname(url);
if (url.port)
host += ":" + url.port;
let search = url.search;
if (!search)
{
let href = url.href;
let queryPos = href.indexOf("?");
if (queryPos != -1)
{
let hashPos = href.indexOf("#");
if (hashPos == -1 || hashPos > queryPos)
search = "?";
}
}
return protocol + "//" + host + url.pathname + search;
}
However, this would make the logic even more complex than it already is, and might still not consider all corner cases. So I went with a more naive approach, which is way simpler and also faster (in particular in the common case, without IDN and no hash). Basically, I reduced the assumptions to a minimum, by just replacing IDN domains and stripping the hash part from URL.href.
Patch Set 1 : #
Total comments: 1
Patch Set 2 : URL.port isn't needed anymore #
Total comments: 3
MessagesTotal messages: 10
|