Skip to content

Commit

Permalink
url: do not decode arbitrary %2e sequences in paths
Browse files Browse the repository at this point in the history
Per a recent change to the URL spec, arbitrary %2e sequences
in URL paths that are not single or double dot segments are
not to be decoded.

Refs: whatwg/url#87
Refs: whatwg/url#156
Refs: web-platform-tests/wpt@d93247d
Fixes: nodejs#10598
PR-URL: nodejs#10602
Reviewed-By: Michal Zasso <targos@protonmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
jasnell authored and italoacasas committed Jan 27, 2017
1 parent e46bdcf commit 824978e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
7 changes: 1 addition & 6 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1214,12 +1214,7 @@ namespace url {
state = kFragment;
}
} else {
if (ch == '%' && p[1] == '2' && TO_LOWER(p[2]) == 'e') {
buffer += '.';
p += 2;
} else {
AppendOrEscape(&buffer, ch, DefaultEncodeSet);
}
AppendOrEscape(&buffer, ch, DefaultEncodeSet);
}
break;
case kCannotBeBase:
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/url-setter-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@
"href": "view-source+http://example.net/home?lang=fr#nav",
"new_value": "\\a\\%2E\\b\\%2e.\\c",
"expected": {
"href": "view-source+http://example.net/\\a\\.\\b\\..\\c?lang=fr#nav",
"pathname": "/\\a\\.\\b\\..\\c"
"href": "view-source+http://example.net/\\a\\%2E\\b\\%2e.\\c?lang=fr#nav",
"pathname": "/\\a\\%2E\\b\\%2e.\\c"
}
},
{
Expand All @@ -967,12 +967,12 @@
}
},
{
"comment": "Bytes already percent-encoded are left as-is, except %2E.",
"comment": "Bytes already percent-encoded are left as-is, including %2E outside dotted segments.",
"href": "http://example.net",
"new_value": "%2e%2E%c3%89té",
"expected": {
"href": "http://example.net/..%c3%89t%C3%A9",
"pathname": "/..%c3%89t%C3%A9"
"href": "http://example.net/%2e%2E%c3%89t%C3%A9",
"pathname": "/%2e%2E%c3%89t%C3%A9"
}
},
{
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/url-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -1847,30 +1847,30 @@
{
"input": "http://example.com/foo/%2e%2",
"base": "about:blank",
"href": "http://example.com/foo/.%2",
"href": "http://example.com/foo/%2e%2",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/foo/.%2",
"pathname": "/foo/%2e%2",
"search": "",
"hash": ""
},
{
"input": "http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar",
"base": "about:blank",
"href": "http://example.com/..bar",
"href": "http://example.com/%2e.bar",
"origin": "http://example.com",
"protocol": "http:",
"username": "",
"password": "",
"host": "example.com",
"hostname": "example.com",
"port": "",
"pathname": "/..bar",
"pathname": "/%2e.bar",
"search": "",
"hash": ""
},
Expand Down Expand Up @@ -2288,15 +2288,15 @@
{
"input": "http://www/foo%2Ehtml",
"base": "about:blank",
"href": "http://www/foo.html",
"href": "http://www/foo%2Ehtml",
"origin": "http://www",
"protocol": "http:",
"username": "",
"password": "",
"host": "www",
"hostname": "www",
"port": "",
"pathname": "/foo.html",
"pathname": "/foo%2Ehtml",
"search": "",
"hash": ""
},
Expand Down

0 comments on commit 824978e

Please sign in to comment.