Skip to content

Commit f6b3fa1

Browse files
committed
fix: simplify Windows path handling to match
spec
1 parent b618015 commit f6b3fa1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/url-state-machine.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,16 +575,18 @@ 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(":") && countSymbols(this.buffer) === 1 &&
579-
infra.isASCIIAlpha(this.buffer.codePointAt(0)) &&
580-
this.input[this.pointer + 1] === p("\\")) {
581-
this.url.scheme = "file";
582-
this.url.host = "";
583-
// Preserve original case from input (buffer was lowercased in scheme start)
584-
const originalDriveLetter = String.fromCodePoint(this.input[this.pointer - 1]);
585-
this.buffer = `${originalDriveLetter}:`;
586-
this.state = "path";
587578
} 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+
}
588590
if (this.stateOverride) {
589591
if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {
590592
return false;

0 commit comments

Comments
 (0)