Skip to content

Commit

Permalink
url: trim leading slashes of file URL paths
Browse files Browse the repository at this point in the history
It should trim the slashes after the colon into three for file URL.

PR-URL: #12203
Refs: web-platform-tests/wpt#5195
Fixes: #11188
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
  • Loading branch information
watilde committed Apr 10, 2017
1 parent 88351a2 commit b470a85
Show file tree
Hide file tree
Showing 3 changed files with 393 additions and 10 deletions.
22 changes: 16 additions & 6 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,14 @@ namespace url {
state = kFileHost;
} else {
if (has_base &&
base->scheme == "file:" &&
base->flags & URL_FLAGS_HAS_PATH &&
base->path.size() > 0 &&
NORMALIZED_WINDOWS_DRIVE_LETTER(base->path[0])) {
url->flags |= URL_FLAGS_HAS_PATH;
url->path.push_back(base->path[0]);
base->scheme == "file:") {
if (NORMALIZED_WINDOWS_DRIVE_LETTER(base->path[0])) {
url->flags |= URL_FLAGS_HAS_PATH;
url->path.push_back(base->path[0]);
} else {
url->flags |= URL_FLAGS_HAS_HOST;
url->host = base->host;
}
}
state = kPath;
continue;
Expand Down Expand Up @@ -1196,6 +1198,14 @@ namespace url {
url->path.push_back(segment);
}
buffer.clear();
if (url->scheme == "file:" &&
(ch == kEOL ||
ch == '?' ||
ch == '#')) {
while (url->path.size() > 1 && url->path[0].length() == 0) {
url->path.erase(url->path.begin());
}
}
if (ch == '?') {
url->flags |= URL_FLAGS_HAS_QUERY;
state = kQuery;
Expand Down
29 changes: 28 additions & 1 deletion test/fixtures/url-setter-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/* WPT Refs:
https://github.com/w3c/web-platform-tests/blob/e48dd15/url/setters_tests.json
https://github.com/w3c/web-platform-tests/blob/3eff1bd/url/setters_tests.json
License: http://www.w3.org/Consortium/Legal/2008/04-testsuite-copyright.html
*/
module.exports =
Expand Down Expand Up @@ -1620,6 +1620,33 @@ module.exports =
"href": "sc://example.net/%23",
"pathname": "/%23"
}
},
{
"comment": "File URLs and (back)slashes",
"href": "file://monkey/",
"new_value": "\\\\",
"expected": {
"href": "file://monkey/",
"pathname": "/"
}
},
{
"comment": "File URLs and (back)slashes",
"href": "file:///unicorn",
"new_value": "//\\/",
"expected": {
"href": "file:///",
"pathname": "/"
}
},
{
"comment": "File URLs and (back)slashes",
"href": "file:///unicorn",
"new_value": "//monkey/..//",
"expected": {
"href": "file:///",
"pathname": "/"
}
}
],
"search": [
Expand Down
Loading

0 comments on commit b470a85

Please sign in to comment.