Skip to content

Commit

Permalink
Refactor "parse relative"
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk authored May 11, 2020
1 parent cff2904 commit 3b7677a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe

## Specification conformance

whatwg-url is currently up to date with the URL spec up to commit [cceb435](https://github.com/whatwg/url/commit/cceb4356cca233b6dfdaabd888263157b2204e44).
whatwg-url is currently up to date with the URL spec up to commit [e5b1dd7](https://github.com/whatwg/url/commit/e5b1dd76df13183b7f123d15880dbdc6a2f37c71).

For `file:` URLs, whose [origin is left unspecified](https://url.spec.whatwg.org/#concept-url-origin), whatwg-url chooses to use a new opaque origin (which serializes to `"null"`).

Expand Down
44 changes: 15 additions & 29 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,32 +679,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 @@ -713,10 +689,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

0 comments on commit 3b7677a

Please sign in to comment.