From f845f2f7db4378fe7a2b7c298cef46b3b573e746 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 24 Jan 2017 15:20:37 -0500 Subject: [PATCH 1/3] Spec update: change path parsing for non-special URLs Follows https://github.com/whatwg/url/pull/213. --- lib/URL-impl.js | 4 ++++ scripts/get-latest-platform-tests.js | 2 +- src/url-state-machine.js | 35 +++++++++++++++++++++------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/URL-impl.js b/lib/URL-impl.js index 9e7d67c..0a394a3 100644 --- a/lib/URL-impl.js +++ b/lib/URL-impl.js @@ -136,6 +136,10 @@ exports.implementation = class URLImpl { return this._url.path[0]; } + if (this._url.path.length === 0) { + return ""; + } + return "/" + this._url.path.join("/"); } diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index 1233928..f43b2b4 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 = "69c16f6b0cb9f067da3652df330cc96b85360e46"; +const commitHash = "825b63235d43b95a12b4a174e3f8243bd990e741"; 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 2e24d1c..295eff1 100644 --- a/src/url-state-machine.js +++ b/src/url-state-machine.js @@ -703,11 +703,12 @@ URLStateMachine.prototype["parse relative"] = function parseRelative(c) { }; URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) { - if (c === p("/") || (isSpecial(this.url) && c === p("\\"))) { + if (isSpecial(this.url) && (c === p("/") || c === p("\\"))) { if (c === p("\\")) { this.parseError = true; + } else if (c === p("/")) { + this.state = "authority"; } - this.state = "special authority ignore slashes"; } else { this.url.username = this.base.username; this.url.password = this.base.password; @@ -959,12 +960,26 @@ URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) { }; URLStateMachine.prototype["parse path start"] = function parsePathStart(c) { - if (isSpecial(this.url) && c === p("\\")) { - this.parseError = true; - } - this.state = "path"; - if (c !== p("/") && !(isSpecial(this.url) && c === p("\\"))) { - --this.pointer; + if (isSpecial(this.url)) { + if (c === p("\\")) { + this.parseError = true; + } + this.state = "path"; + + if (c !== p("/") && c !== p("\\")) { + --this.pointer; + } + } else if (!this.stateOverride && c === p("?")) { + this.url.query = ""; + this.state = "query"; + } else if (!this.stateOverride && c === p("#")) { + this.url.fragment = ""; + this.state = "fragment"; + } else if (c !== undefined) { + this.state = "path"; + if (c !== p("/")) { + --this.pointer; + } } return true; @@ -1126,7 +1141,9 @@ function serializeURL(url, excludeFragment) { if (url.cannotBeABaseURL) { output += url.path[0]; } else { - output += "/" + url.path.join("/"); + for (const string of url.path) { + output += "/" + string; + } } if (url.query !== null) { From 9dca13ddb744a34bf47b5974840d8c84fb532262 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 30 Jan 2017 20:03:04 -0800 Subject: [PATCH 2/3] Fix per review --- scripts/get-latest-platform-tests.js | 2 +- src/url-state-machine.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index f43b2b4..e045632 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 = "825b63235d43b95a12b4a174e3f8243bd990e741"; +const commitHash = "4ea8eae2fd807ffd22e84f3c2f2ca12f798f8206"; 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 295eff1..85bad9c 100644 --- a/src/url-state-machine.js +++ b/src/url-state-machine.js @@ -706,9 +706,10 @@ URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash( if (isSpecial(this.url) && (c === p("/") || c === p("\\"))) { if (c === p("\\")) { this.parseError = true; - } else if (c === p("/")) { - this.state = "authority"; } + this.state = "special authority ignore slashes"; + } else if (c === p("/")) { + this.state = "authority"; } else { this.url.username = this.base.username; this.url.password = this.base.password; From f6067f457188596a3477aa609fd3cfd8675ebb9d Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 31 Jan 2017 14:37:30 -0800 Subject: [PATCH 3/3] Update to latest master WPTs --- scripts/get-latest-platform-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index e045632..66ffc42 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 = "4ea8eae2fd807ffd22e84f3c2f2ca12f798f8206"; +const commitHash = "cd5cce9780f84cee679919679b8199084ea96d54"; 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`;