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

Refactor "parse relative" #149

Merged
merged 3 commits into from
May 11, 2020
Merged
Changes from 2 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
44 changes: 15 additions & 29 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,32 +684,8 @@ URLStateMachine.prototype["parse path or authority"] = function parsePathOrAutho

URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
this.url.scheme = this.base.scheme;
if (isNaN(c)) {
this.url.username = this.base.username;
this.url.password = this.base.password;
this.url.host = this.base.host;
this.url.port = this.base.port;
this.url.path = this.base.path.slice();
this.url.query = this.base.query;
} else if (c === p("/")) {
if (c === p("/")) {
this.state = "relative slash";
} else if (c === p("?")) {
this.url.username = this.base.username;
this.url.password = this.base.password;
this.url.host = this.base.host;
this.url.port = this.base.port;
this.url.path = this.base.path.slice();
this.url.query = "";
this.state = "query";
} else if (c === p("#")) {
this.url.username = this.base.username;
this.url.password = this.base.password;
this.url.host = this.base.host;
this.url.port = this.base.port;
this.url.path = this.base.path.slice();
this.url.query = this.base.query;
this.url.fragment = "";
this.state = "fragment";
} else if (isSpecial(this.url) && c === p("\\")) {
this.parseError = true;
this.state = "relative slash";
Expand All @@ -718,10 +694,20 @@ URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
this.url.password = this.base.password;
this.url.host = this.base.host;
this.url.port = this.base.port;
this.url.path = this.base.path.slice(0, this.base.path.length - 1);

this.state = "path";
--this.pointer;
this.url.path = this.base.path.slice();
this.url.query = this.base.query;
if (c === p("?")) {
this.url.query = "";
this.state = "query";
} else if (c === p("#")) {
this.url.fragment = "";
this.state = "fragment";
} else if (!isNaN(c)) {
this.url.query = null;
this.url.path.pop();
this.state = "path";
--this.pointer;
}
}

return true;
Expand Down