Skip to content

Commit fe79067

Browse files
committed
feat: implement Windows file path handling per WHATWG URL spec
1 parent 4ff0e2e commit fe79067

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/url-state-machine.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,16 @@ URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, c
575575
URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
576576
if (infra.isASCIIAlphanumeric(c) || c === p("+") || c === p("-") || c === p(".")) {
577577
this.buffer += cStr.toLowerCase();
578+
} else if (c === p(":") && this.buffer.length === 1 &&
579+
infra.isASCIIAlpha(this.buffer.codePointAt(0)) &&
580+
this.input[this.pointer + 1] === p("\\") &&
581+
!this.stateOverride) {
582+
this.url.scheme = "file";
583+
this.url.host = "";
584+
// Preserve original case of drive letter from input
585+
const driveLetter = String.fromCodePoint(this.input[this.pointer - 1]);
586+
this.buffer = `${driveLetter}:`;
587+
this.state = "path";
578588
} else if (c === p(":")) {
579589
if (this.stateOverride) {
580590
if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {

scripts/get-latest-platform-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const path = require("path");
1313
// 1. Go to https://github.com/web-platform-tests/wpt/tree/master/url
1414
// 2. Press "y" on your keyboard to get a permalink
1515
// 3. Copy the commit hash
16-
const commitHash = "40fc257a28faf7c378f59185235685ea8684e8f4";
16+
const commitHash = "82f211de961cdbf0deed06083b60d1077fd39f02";
1717

1818
const urlPrefix = `https://raw.githubusercontent.com/web-platform-tests/wpt/${commitHash}/url/`;
1919
const targetDir = path.resolve(__dirname, "..", "test", "web-platform-tests");

0 commit comments

Comments
 (0)