Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
fs: make mkdtemp accept buffers and URL#48828
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
976f66b to f61da69Comparelib/internal/fs/utils.js Outdated
| // Template strings passed to the mkdtemp() family of functions should not | ||
| // end with 'X' because they are handled inconsistently across platforms. | ||
| if(nonPortableTemplateWarn&&StringPrototypeEndsWith(template,'X')){ | ||
| if(nonPortableTemplateWarn&&StringPrototypeEndsWith(`${template}`,'X')){ |
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.
String.prototype.endsWith always strigifies this value but explicit coercion wouldn't hurt
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 think it would be a mistake to attempt to stringify a TypedArray, let's not bother with this warning if the template is not a string, wdyt?
| if(nonPortableTemplateWarn&&StringPrototypeEndsWith(`${template}`,'X')){ | |
| if(nonPortableTemplateWarn&&typeoftemplate==='string'&&StringPrototypeEndsWith(template,'X')){ |
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.
Oh that's right, it can be native Uint8Array, too. Fixed that in the actual functions. 😅
As for warning, AFAICT there's no utf character that ends with 0x58 except for one-byte X, so Array.prototype.at.call(template, -1) === 0x58 should suffice for buffers.
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 it's an always correct assumption that the system would be using a UTF encoding set, but maybe it's fair to consider so as it's certainly very common 🤔 but probably folks who are using a Buffer/Uint8Array are doing so precisely so it can work on weird encoding sets? Maybe it's not worth overthinking it, it's just emitting a warning, so it's not like it would block anyone to have false positive.
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 warning makes sense because the underlying implementation still might get confused.
glibc performs multibyte-unfriendly check with strspn, and it might be likely for mkdtemp on exotic platforms supporting prefixes longer than 6 to be as rough as for (int i = strlen(template); template[--i] == 'X'; template[i] = getRandomChar()){}.
IMHO if someone writes precise code for specific platforms and charsets, it's probably up to them to simply ignore warning about template not being portable.
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.
This comment was marked as outdated.
This comment was marked as outdated.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as outdated.
This comment was marked as outdated.
nodejs-github-bot commented Jul 20, 2023
cf63c24 to e589bd3Compare68703a6 to 85c0566CompareLiviaMedeiros commented Jul 21, 2023
Rebased with 68703a6 for linter |
LiviaMedeiros commented Jul 26, 2023
Landed in 6cd6789...1eae568 |
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs#48828 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: #48828 Backport-PR-URL: #50669 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs/node#48828 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
PR-URL: nodejs/node#48828 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
mkdtemp()seems to be the onlyfsmethod that doesn't supportURLobjects yet.