Skip to content

Commit fd03587

Browse files
mertcanaltinclaude
andcommitted
fix: implement Windows file path handling per WHATWG URL spec
Implements Windows drive letter detection as specified in whatwg/url#874. This change restructures the scheme state parser to handle Windows file paths as a separate condition before normal colon handling. Key changes: - Windows drive letter check moved to separate else-if block (spec lines 2251-2262) - Original case of drive letter preserved from input - Removed nested if and early return for cleaner flow Test results: - 5363/5367 tests passing - All Windows path tests passing (C:\path, a:\file, etc.) - 3 unrelated IDNA test failures remain Spec reference: https://url.spec.whatwg.org/#scheme-state Related PR: web-platform-tests/wpt#53459 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f6b3fa1 commit fd03587

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/url-state-machine.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -575,18 +575,17 @@ 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(":")) {
579-
// Windows drive letter handling
580-
if (this.buffer.length === 1 && infra.isASCIIAlpha(this.buffer.codePointAt(0)) &&
581-
this.input[this.pointer + 1] === p("\\") && !this.stateOverride) {
582-
this.url.scheme = "file";
583-
this.url.host = "";
584-
// Preserve the original case of the drive letter from input
585-
const driveLetter = String.fromCodePoint(this.input[this.pointer - 1]);
586-
this.buffer = `${driveLetter}:`;
587-
this.state = "path";
588-
return true;
589-
}
590589
if (this.stateOverride) {
591590
if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {
592591
return false;

0 commit comments

Comments
 (0)