Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec update: change path parsing for non-special URLs #70

Merged
merged 3 commits into from
Jan 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "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`;
Expand Down
34 changes: 26 additions & 8 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,13 @@ 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;
}
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;
Expand Down Expand Up @@ -959,12 +961,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 +1142,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