Skip to content

Commit

Permalink
Spec update: Windows drive letter quirk in the file slash state
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev authored and domenic committed Sep 25, 2017
1 parent be9038b commit b53b6e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe

## Current status

whatwg-url is currently up to date with the URL spec up to commit [19e0ffa](https://github.com/whatwg/url/commit/19e0ffa225ccc34dde7e76e30fca538d57fa52f6).
whatwg-url is currently up to date with the URL spec up to commit [2eef975](https://github.com/whatwg/url/commit/2eef975e989cb5ae2d62467394778fd6778ddec9).

## API

Expand Down
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Expand Up @@ -19,7 +19,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 = "785ec55ddc2dc2e5dfecac65832d68c82f72e50b";
const commitHash = "5d149f011b36c84541186414c783f0ea18d14942";

// Have to use RawGit as JSDOM.fromURL checks Content-Type header.
const urlPrefix = `https://rawgit.com/w3c/web-platform-tests/${commitHash}/url/`;
Expand Down
15 changes: 10 additions & 5 deletions src/url-state-machine.js
Expand Up @@ -884,6 +884,13 @@ URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) {

const fileOtherwiseCodePoints = new Set([p("/"), p("\\"), p("?"), p("#")]);

function startsWithWindowsDriveLetter(input, pointer) {
const length = input.length - pointer;
return length >= 2 &&
isWindowsDriveLetterCodePoints(input[pointer], input[pointer + 1]) &&
(length === 2 || fileOtherwiseCodePoints.has(input[pointer + 2]));
}

URLStateMachine.prototype["parse file"] = function parseFile(c) {
this.url.scheme = "file";

Expand All @@ -909,10 +916,7 @@ URLStateMachine.prototype["parse file"] = function parseFile(c) {
this.url.fragment = "";
this.state = "fragment";
} else {
if (this.input.length - this.pointer - 1 === 0 || // remaining consists of 0 code points
!isWindowsDriveLetterCodePoints(c, this.input[this.pointer + 1]) ||
(this.input.length - this.pointer - 1 >= 2 && // remaining has at least 2 code points
!fileOtherwiseCodePoints.has(this.input[this.pointer + 2]))) {
if (!startsWithWindowsDriveLetter(this.input, this.pointer)) {
this.url.host = this.base.host;
this.url.path = this.base.path.slice();
shortenPath(this.url);
Expand All @@ -938,7 +942,8 @@ URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
}
this.state = "file host";
} else {
if (this.base !== null && this.base.scheme === "file") {
if (this.base !== null && this.base.scheme === "file" &&
!startsWithWindowsDriveLetter(this.input, this.pointer)) {
if (isNormalizedWindowsDriveLetterString(this.base.path[0])) {
this.url.path.push(this.base.path[0]);
} else {
Expand Down

0 comments on commit b53b6e8

Please sign in to comment.