From 6ff27fdb7372d82c2799e7d84cc44ea8b69b86c2 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 3 Apr 2017 14:14:40 +0900 Subject: [PATCH] Spec update: trim leading slashes of file URL paths Follows https://github.com/whatwg/url/pull/278. --- README.md | 2 +- scripts/get-latest-platform-tests.js | 2 +- src/url-state-machine.js | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a20cea..f6df05d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe ## Current Status -whatwg-url is currently up to date with the URL spec up to commit [728656](https://github.com/whatwg/url/commit/72865694ca2fc54b1c5fcfea9bed9f6b34e365ac). +whatwg-url is currently up to date with the URL spec up to commit [a562c5](https://github.com/whatwg/url/commit/a562c55d659e1657d1dc9f9fad600bd9f9d70d82). ## API diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index 42498d4..b2a038f 100644 --- a/scripts/get-latest-platform-tests.js +++ b/scripts/get-latest-platform-tests.js @@ -14,7 +14,7 @@ const request = require("request"); // 1. Go to https://github.com/w3c/web-platform-tests/tree/master/url // 2. Press "y" on your keyboard to get a permalink // 3. Copy the commit hash -const commitHash = "e48dd15f848ea7758960fa2dad352253572339c9"; +const commitHash = "0444344a4ace9dba478899c92de5a1d6d561cc54"; const sourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/urltestdata.json`; const setterSourceURL = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}/url/setters_tests.json`; diff --git a/src/url-state-machine.js b/src/url-state-machine.js index 2c981e5..047052f 100644 --- a/src/url-state-machine.js +++ b/src/url-state-machine.js @@ -963,8 +963,10 @@ URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) { this.state = "file host"; } else { if (this.base !== null && this.base.scheme === "file") { - if (this.base.path.length > 0 && isNormalizedWindowsDriveLetterString(this.base.path[0])) { + if (isNormalizedWindowsDriveLetterString(this.base.path[0])) { this.url.path.push(this.base.path[0]); + } else { + this.url.host = this.base.host; } } this.state = "path"; @@ -1062,6 +1064,12 @@ URLStateMachine.prototype["parse path"] = function parsePath(c) { this.url.path.push(this.buffer); } this.buffer = ""; + if (this.url.scheme === "file" && (c === undefined || c === p("?") || c === p("#"))) { + while (this.url.path.length > 1 && this.url.path[0] === "") { + this.parseError = true; + this.url.path.shift(); + } + } if (c === p("?")) { this.url.query = ""; this.state = "query";