-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
url: return backslashes from fileURLToPath on Windows #25349
Conversation
@@ -1289,6 +1291,7 @@ function getPathFromURLWin32(url) { | |||
} | |||
} | |||
} | |||
pathname = pathname.replace(forwardSlashRegEx, '\\'); |
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.
If you think it makes anything more readable here or elsewhere, you can use path.win32.sep
and/or path.posix.sep
and/or path.sep
. (No strong opinion from me on whether or not they should be used here. Just pointing 'em out in case you didn't know about 'em.)
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.
I'm not sure I have a strong opinion either.
const url = require('url'); | ||
|
||
// Input must be string or URL | ||
assert.throws(() => url.fileURLToPath(null)); |
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.
Linter is complaining that there is no second argument in assert.throws()
here and elsewhere. (You can run the JS linter locally with make lint-js
or, I believe, vcbuild lint-js
. Running make test
or, I think, vcbuild test
should run the linter as well.) So this instance might be:
assert.throws(() => { url.fileURLToPath(null); }, { code: 'ERR_INVALID_ARG_TYPE' });
We require the second argument because changing the code
of the error is considered a breaking change. So we want the test to validate the code
property at least.
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.
I added the second args. Thanks!
FWIW there is already a PR for this change in #25324 |
7034c68
to
a9e54a8
Compare
@mscdex Ah, I didn't the other PR. Feel free to use that one if the group think it's higher quality. (Although of course I think this one is better! 😉) |
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.
Looks good, and nice to have lots of tests here definitely.
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 has better tests than my #25324, I'm going to close that other PR.
a9e54a8
to
fb44f14
Compare
@@ -63,7 +63,7 @@ if (common.isWindows) { | |||
code: 'ERR_INVALID_ARG_VALUE', | |||
type: TypeError, | |||
message: 'The argument \'path\' must be a string or Uint8Array without ' + | |||
'null bytes. Received \'c:/tmp/\\u0000test\'' | |||
'null bytes. Received \'c:\\\\tmp\\\\\\u0000test\'' |
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.
Updated this test after I noticed the error.
The reason for multiple backslashes is that ERR_INVALID_ARG_VALUE calls inspect
on the invalid argument value.
Is the failure
because I force-pushed my latest update? Or something else? Thanks for your patience : ) |
I don't know, but it happens sometimes. Here's a Rebuild: https://ci.nodejs.org/job/node-test-commit-windows-fanned/23794/ |
Let’s see; rebuild CI: https://ci.nodejs.org/job/node-test-pull-request/19996/ |
https://ci.nodejs.org/job/node-test-pull-request/19965/ passed except for Windows and https://ci.nodejs.org/job/node-test-commit-windows-fanned/23794/ passed for Windows, so I think we're good as far as CI goes. (No commits have been pushed or force-pushed since those runs.) |
Landed in 7237eaa. |
PR-URL: nodejs#25349 Fixes: nodejs#25265 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Fixes: #25265
Fixes
url.fileURLToPath
to return backslash-separated paths instead of forward-separated paths on Windows. This is my first PR to the repo so any and all feedback is welcome.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes