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 8834089
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 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
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 = "special authority ignore slashes";
}
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 8834089

Please sign in to comment.