-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Percent-decoding entire URL components is not valid #180
Comments
Ah my bad - the path example is okay because var url = new URL("http://example/?show=Tom%26Jerry&episode=3");
url.href;
// 'http://example/?show=Tom%26Jerry&episode=3'
// ^^^ - ❗️
url.searchParams.get("show");
// 'Tom&Jerry'
url.search = decodeURIComponent(url.search);
url.href;
// 'http://example/?show=Tom&Jerry&episode=3'
// ^ - ❗️
url.searchParams.get("show");
// 'Tom' |
As far as I remember |
The problem is that |
These operations are not valid:
normalize-url/index.js
Lines 178 to 183 in 3c7235e
normalize-url/index.js
Lines 243 to 245 in 3c7235e
Since URLs are a textual format, certain characters have semantic meaning. Percent-encoding can be used to escape those characters. For example, if we want a single path component named "AC/DC", we'll have a problem, because "/" can mean a path separator:
So instead, we have to escape the use of "/" within name "AC/DC":
If you percent-decode the entire path string, we irreversibly lose the information that "AC/DC" was supposed to be a single path component.
Instead, the correct way to do this is to split the component (still escaped) up in to its constituent parts, decode each component, escape any characters with semantic meaning, and join them up again. For the path, that means breaking it up in to path components and ensuring "/" and "" characters are escaped again in each component before you rebuild the path string. For the query, it means doing the same for each key and value (not each key-value pair - they need to be broken down in to their smallest subcomponents).
The text was updated successfully, but these errors were encountered: