Skip to content
Permalink
Browse files

url: trim leading slashes of file URL paths

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 b470a85f071ccdde0e24b48a6fe8389b0a54750d
Showing with 393 additions and 10 deletions.
  1. +16 −6 src/node_url.cc
  2. +28 −1 test/fixtures/url-setter-tests.js
  3. +349 −3 test/fixtures/url-tests.js
@@ -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;
@@ -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;
@@ -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 =
@@ -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": [

0 comments on commit b470a85

Please sign in to comment.
You can’t perform that action at this time.