url: file URL path normalization#35477
Conversation
1de4ef4 to
b6e0aa2
Compare
|
This might fix #35429 👀? |
b6e0aa2 to
fea5da9
Compare
fea5da9 to
a843655
Compare
|
/cc @nodejs/tsc because semver-major. |
There was a problem hiding this comment.
One pattern for a cross platform URL construction is:
new URL('//' + path.resolve('path'), 'file:')where that works in both Windows and Posix because the // in the Posix case is deduped.
Under this PR it would resolve to file:////path/to/path and the four /'s will lead to some module system issues.
Ideally this should be corrected specifically for file: URLs in the WhatWG spec, but otherwise we should be renormalizing these in the module system otherwise at least now to avoid these cases I think.
We should also have tests for fileURLToPath(new URL('file:////path')) and pathToFileURL('//path') to verify these new cases too.
| "hostname": "spider", | ||
| "port": "", | ||
| "pathname": "/", | ||
| "pathname": "///", |
There was a problem hiding this comment.
This is a little confusing to me. Why are the / in paths no longer being deduped? I am concerned this will be breaking for modules users who make this mistake.
|
@guybedford You've approved this PR but left a lengthy comment expressing some concerns. Are the concerns things that need to be addressed by the modules team before this makes it into a release? Or is resolution of those issues a prerequisite before landing this change? |
|
@Trott unfortunately I think this has some problems for the modules system as there is the potential of One simple approach could be to have the module resolver throw for |
guybedford
left a comment
There was a problem hiding this comment.
There is a concern that file://// URLs in the module registry lead to duplicate loads. We should likely throw in the resolver or dig into the spec differences here.
|
@watilde do you have any further background on why |
|
I think we should absolutely follow the standard and make this change. Any possible impact to the modules subsystem should be dealt with there. That said, there's nothing saying that we cannot inject a flag that forces a revert back to original behavior if it is absolutely needed. e.g. // Implements the new behavior $ node -pe "new URL('////path/to/resolve', 'file:')"// Implements the old behavior $ node --original-url-path-normalization "new URL('////path/to/resolve', 'file:')" Yes, this would allow some inconsistency in behavior (similar to |
|
@jasnell I agree we should update to w/e the standard is but there is some lack of clarity on what to do w/ comparison of these URLs with multiple adjacent |
guybedford
left a comment
There was a problem hiding this comment.
We disussed this in the meeting but weren't able to come to any conclusions there unfortunately.
Discussing further with @bmeck it appears the major module resolution cases already do handle normalization fine, and it is only when using --preserve-symlinks that these resolutions can creep into the module registry. A follow-up patch to apply a path.resolve normalization in the --preserve-symlinks case can fix any of these issues up, but is not on the critical path to landing on this PR as it is a much wider edge case.
In addition I have posted a proposal at whatwg/url#552 for handling deduplication.
This PR likely will still cause breaks for URL consumers in the ecosystem, but it seems moving forward with landing would be best at this point.
|
@guybedford Thank you for your effort to carefully clarify the impact with the team and sharing back the result! That is very helpful feedback and I agreed on that we should follow up for @bmeck Thank you for your participation as well. I'd appreciate if you can update the review status based on the discussion. Let me cc @nodejs/tsc again for one more review and approval before landing, because this is |
|
I think if we deduplicate |
|
Landed in bb62f4a |
|
On master some tests fail which look related to this PR. see e.g. https://ci.nodejs.org/job/node-test-binary-windows-native-suites/5470/#showFailuresLink |
|
test/cctest/test_url.cc has a |
|
@Flarna Thank you for catching that. I'll open PR for tests shortly |
Refs: whatwg/url#544
Refs: web-platform-tests/wpt#25716
Fixes: #35429
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesrequests.md#commit-message-guidelines)