url: validate pathToFileURL(path) argument as string#49161
Merged
LiviaMedeiros merged 1 commit intonodejs:mainfrom Aug 31, 2023
Merged
url: validate pathToFileURL(path) argument as string#49161LiviaMedeiros merged 1 commit intonodejs:mainfrom
pathToFileURL(path) argument as string#49161LiviaMedeiros merged 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Collaborator
joyeecheung
approved these changes
Aug 14, 2023
anonrig
reviewed
Aug 14, 2023
lib/internal/url.js
Outdated
| } | ||
|
|
||
| function pathToFileURL(filepath) { | ||
| validateString(filepath, 'path'); |
Member
There was a problem hiding this comment.
This is an extremely hot path, hence my comment:
We already validate this for !(isWindows && StringPrototypeStartsWith(filepath, '\\\\')) case (path.resolve handles the validation). Can you make sure this only runs when the OS is windows? No need to run it twice for non-windows environments.
Member
Author
There was a problem hiding this comment.
This check also fixes The "paths[0]" argument must be of type string. error message that kinda implies that this method may take more than one argument.
I guess we can keep the internal/url version as is (so it won't affect performance in core), but instead of re-exporting it directly in url make a thin wrapper that validates input, wdyt?
This was referenced Aug 15, 2023
aduh95
approved these changes
Aug 21, 2023
This comment was marked as outdated.
This comment was marked as outdated.
This was referenced Aug 23, 2023
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This was referenced Aug 27, 2023
This comment was marked as outdated.
This comment was marked as outdated.
This was referenced Aug 29, 2023
Collaborator
This comment was marked as outdated.
This comment was marked as outdated.
18 tasks
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
PR-URL: nodejs#49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
c940437 to
57e78bc
Compare
Member
Author
|
Landed in 57e78bc |
This was referenced Sep 1, 2023
UlisesGascon
pushed a commit
that referenced
this pull request
Sep 10, 2023
PR-URL: #49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Merged
alexfernandez
pushed a commit
to alexfernandez/node
that referenced
this pull request
Nov 1, 2023
PR-URL: nodejs#49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos
pushed a commit
that referenced
this pull request
Nov 27, 2023
PR-URL: #49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher
added a commit
to sercher/graaljs
that referenced
this pull request
Apr 25, 2024
PR-URL: nodejs/node#49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher
added a commit
to sercher/graaljs
that referenced
this pull request
Apr 25, 2024
PR-URL: nodejs/node#49161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since
url.pathToFileURL()is exposed as a part of public API, it should validate input value.Before this change, non-strings were rejected in
path.resolve()with confusingThe "paths[0]" argument must be of type string.message.On Windows, input was directly passed into
StringPrototypeStartsWith(), causing either confusing errors or implicit coercion to string.