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

Implement proposal for file URL path normalisation #170

Merged
merged 4 commits into from
Sep 30, 2020
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
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 [83adf0c](https://github.com/whatwg/url/commit/83adf0c9ca9a88948e1e5d93374ffded04eec727).
whatwg-url is currently up to date with the URL spec up to commit [47efa00](https://github.com/whatwg/url/commit/47efa0043d677fb51169cde72b60703bd8de83e3).

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
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ process.on("unhandledRejection", err => {
// 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 = "551c9d604fb8b97d3f8c65793bb047d15baddbc2";
const commitHash = "11a6ab8df5f84d40d8818afe8773dd519e5263e4";

const urlPrefix = `https://raw.githubusercontent.com/web-platform-tests/wpt/${commitHash}/url/`;
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");
Expand Down
20 changes: 4 additions & 16 deletions src/url-state-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ URLStateMachine.prototype["parse file"] = function parseFile(c) {
shortenPath(this.url);
} else {
this.parseError = true;
this.url.host = null;
this.url.path = [];
}

Expand All @@ -889,13 +888,12 @@ URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
}
this.state = "file host";
} else {
if (this.base !== null && this.base.scheme === "file" &&
!startsWithWindowsDriveLetter(this.input, this.pointer)) {
if (isNormalizedWindowsDriveLetterString(this.base.path[0])) {
if (this.base !== null && this.base.scheme === "file") {
if (!startsWithWindowsDriveLetter(this.input, this.pointer) &&
isNormalizedWindowsDriveLetterString(this.base.path[0])) {
this.url.path.push(this.base.path[0]);
} else {
this.url.host = this.base.host;
}
this.url.host = this.base.host;
}
this.state = "path";
--this.pointer;
Expand Down Expand Up @@ -983,21 +981,11 @@ URLStateMachine.prototype["parse path"] = function parsePath(c) {
this.url.path.push("");
} else if (!isSingleDot(this.buffer)) {
if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) {
if (this.url.host !== "" && this.url.host !== null) {
this.parseError = true;
this.url.host = "";
}
this.buffer = this.buffer[0] + ":";
}
this.url.path.push(this.buffer);
}
this.buffer = "";
if (this.url.scheme === "file" && (c === undefined || c === p("?") || c === p("#"))) {
while (this.url.path.length > 1 && this.url.path[0] === "") {
this.parseError = true;
this.url.path.shift();
}
}
if (c === p("?")) {
this.url.query = "";
this.state = "query";
Expand Down