-
-
Notifications
You must be signed in to change notification settings - Fork 103
feat: implement Windows file path handling in URL parsing #304
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
base: main
Are you sure you want to change the base?
feat: implement Windows file path handling in URL parsing #304
Conversation
Per @annevk's guidance in whatwg/url#874, the implementation is now Implementation SummaryCore Rules (Implemented):
Test Results:
Changes Made:
WPT Tests: Updated in web-platform-tests/wpt#53459 Ready for review! 🚀 |
- Single ASCII letter + :\ → Windows file path - Multi-letter drives (CC:\, ABC:\) → Failure - Non-letter drives (1:\, @:\) → Failure - Normal schemes with backslash → Opaque path (valid) Per @annevk's feedback in whatwg/url#874
- Add 'u' flag to all regex patterns - Use template literals instead of string concatenation - Fix whitespace before property access
Updated tests to reflect simplified Windows path handling: 1. Multi-letter drives (CC:\, ABC:\) are now parsed as normal URLs - CC:\path → scheme: cc, path: \path (not failure) - 1:\path → failure (schemes must start with ASCII letter) - @:\path → failure (@ not valid in scheme) 2. UNC paths without base URL should fail - \\server\share → failure (no special UNC handling) - UNC paths with file: base still work via relative parsing This aligns with whatwg/url#874 guidance: "Why would we not parse CC:\path as we do today?" Only single ASCII letter + :\ should be treated as Windows file path. Everything else uses normal URL parsing. Related: whatwg/url#874, jsdom/whatwg-url#304
] | ||
.map(async file => { | ||
const res = await fetch(`${urlPrefix}${file}`); | ||
await fs.writeFile(path.resolve(targetDir, file), res.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this change.
// Only convert single ASCII letter + :\ pattern (e.g., C:\, D:\) | ||
// Note: Only backslash (\), not forward slash (/) | ||
// Everything else goes through normal URL parsing | ||
if (!stateOverride && !this.url.scheme && /^[a-zA-Z]:\\/u.test(this.input)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't match the spec text at https://github.com/whatwg/url/pull/874/files#diff-29243b3b9b716b55c6a61970b0c4864f464b139d397fb961a05bb6e1e2b97cabR2251 . Please translate the spec text directly.
// Handle Windows file paths if no state override | ||
// Only convert single ASCII letter + :\ pattern (e.g., C:\, D:\) | ||
// Note: Only backslash (\), not forward slash (/) | ||
// Everything else goes through normal URL parsing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments are not useful (and do not appear in the spec).
// Everything else goes through normal URL parsing | ||
if (!stateOverride && !this.url.scheme && /^[a-zA-Z]:\\/u.test(this.input)) { | ||
const converted = this.input.replace(/\\/gu, "/"); | ||
this.input = `file:///${converted}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes do not match the spec text at https://github.com/whatwg/url/pull/874/files#diff-29243b3b9b716b55c6a61970b0c4864f464b139d397fb961a05bb6e1e2b97cabR2256
Implements Windows file path handling as part of the WHATWG URL
spec change (whatwg/url#874).
Changes
percent-encoded Unicode
Implementation
When a Windows file path is detected at the start of URL parsing: