-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
child_process: allow URL instances as paths to executables
#49031
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?
Conversation
test/common/index.js
Outdated
| [new URL('file:///C:/Windows/system32/cmd.exe'), ['/d', '/c', 'cd']] : | ||
| [new URL('file:///bin/pwd'), []]; |
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.
Why these changes? Are we sure these absolute paths are safe assumptions?
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.
Not 100% sure and I'd like to see if it's not the case on any platform covered by CI first.
Then it will most likely be moved to separate test-child-process-urlfile.mjs test.
If there is a concise&robust way to get absolute url or absolute path to pwd or any other convenient good-for-test executable, or if we can create one in fixtures, I'd like to know.
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 would guess the "where"/"which" commands should generally be available, even outside of CI since tests should work locally too.
Failed to start CI- Validating Jenkins credentials ✘ Jenkins credentials invalidhttps://github.com/nodejs/node/actions/runs/5774680936 |
| changes: | ||
| - version: REPLACEME | ||
| pr-url: https://github.com/nodejs/node/pull/49031 | ||
| description: The `command` parameter can be a WHATWG `URL` object using |
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.
The word object hints towards an actual javascript object with URL class properties, but there isn't any test to check towards it.
| description: The `command` parameter can be a WHATWG `URL` object using | |
| description: The `command` parameter can be a WHATWG `URL` instance using |
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.
isURL() is duck-typed:
Lines 761 to 763 in d150316
| function isURL(self) { | |
| return Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined); | |
| } |
so it probably makes sense? The same term is used in other entries here as well.
| } | ||
|
|
||
| { | ||
| const stdout = cp.spawnSync(...pwdCommandAndOptions).stdout; |
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.
Can you also add a test where the legacy url class is used? We need to make sure it does exactly what we want it to be.
| const pwdFullPath = `${cp.execSync(whichCommand)}`.trim(); | ||
| const pwdUrl = pathToFileURL(pwdFullPath); | ||
| const pwdCommandAndOptions = isWindows ? | ||
| [pwdUrl, ['/d', '/c', 'cd'], { cwd: pathToFileURL(cwd) }] : |
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.
Can you also add a test where javascript object representation of the URL is used?
| function normalizeSpawnArguments(file, args, options) { | ||
| validateString(file, 'file'); | ||
| validateArgumentNullCheck(file, 'file'); | ||
| file = getValidatedPath(file, 'file'); |
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.
validatePath inside getValidatedPath also accepts buffers. Can you add a test for it as well?
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.
Nice catch! I guess it should be restricted to string or stringified URL, at least for now.
|
cc @nodejs/url |
|
|
||
| throws( | ||
| () => cp.execFileSync(...pwdCommandAndOptions), | ||
| { code: 'ERR_INVALID_ARG_TYPE' }, |
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.
Can you be specific, or at least add comment about what this line is testing? It is really cryptic atm.
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.
Added tests for specific errors, added brief comments.
This comment was marked as outdated.
This comment was marked as outdated.
7ca5ecf to
71a2fef
Compare
Allow
URLinstances to be passed asfileparameters andexecPathoptions. For example: