Skip to content

fix: reject Windows file paths in can_parse#957

Closed
mertcanaltin wants to merge 2 commits into
ada-url:mainfrom
mertcanaltin:fix/can-parse-windows-path
Closed

fix: reject Windows file paths in can_parse#957
mertcanaltin wants to merge 2 commits into
ada-url:mainfrom
mertcanaltin:fix/can-parse-windows-path

Conversation

@mertcanaltin

Copy link
Copy Markdown
Contributor

reject Windows file paths in can_parse

I tried to solve this place out : nodejs/node#58578 (comment)

Comment thread src/implementation.cpp
Comment on lines +53 to +55
if (helpers::is_windows_file_path(input)) {
return false;
}

@anonrig anonrig Jun 13, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you point us to where in the URL spec this is returning false? Chrome and Safari returns true...

> URL.canParse("file:///C:/path/file.node")
true
> URL.canParse("C:\\path\\file.node")
true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually allowed. https://url.spec.whatwg.org/#file-host-state

If state override is not given and buffer is a Windows drive letter, file-invalid-Windows-drive-letter-host validation error, set state to path state.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you apply the same change to URL parser, not the can_parse() method, you'll see that it breaks web-platform tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, instead of rejecting Windows file paths
Is it a healthy method to normalize them with the file:/// protocol ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the library provides is WHATWG URL support. If the result disagrees with your expectations make sure first to check the WHATWG URL specification. If you disagree with it, you should take your concerns with WHATWG.

We may have bugs but a bug is a disagreement with WHATWG.

@anonrig anonrig requested review from jasnell and lemire June 13, 2025 19:17
@lemire

lemire commented Jun 13, 2025

Copy link
Copy Markdown
Member

At a glance this PR appears to break the specification.

@mertcanaltin

Copy link
Copy Markdown
Contributor Author

At a glance this PR appears to break the specification.

@lemire Thank you for the clear guidance. I understand now that we should follow the WHATWG URL spec strictly.

I've opened an issue in WHATWG to discuss the Windows file path handling: whatwg/url#873

I'll keep the library's behavior aligned with the spec while we discuss this in WHATWG.

@lemire

lemire commented Jun 13, 2025

Copy link
Copy Markdown
Member

I am closing this PR since @mertcanaltin reported the issue to WHATWG. It is understood that if the standard changes, we will reopen such a PR.

@lemire lemire closed this Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants