Skip to content

Commit

Permalink
Spec update: change path parsing for non-special URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jan 24, 2017
1 parent 7465c23 commit f845f2f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lib/URL-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
35 changes: 26 additions & 9 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f845f2f

Please sign in to comment.