fs: add encoding option to glob and globSync#62951
Open
maruthang wants to merge 1 commit intonodejs:mainfrom
Open
fs: add encoding option to glob and globSync#62951maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang wants to merge 1 commit intonodejs:mainfrom
Conversation
fs.glob, fs.globSync, and fsPromises.glob always decoded directory entries as UTF-8, so on POSIX any non-UTF-8 bytes in file names were silently replaced with U+FFFD and the original byte sequence could not be recovered. Add an `encoding` option mirroring fs.readdir. When set to 'buffer', glob returns Buffer paths and (when withFileTypes is true) Dirents whose `name` and `parentPath` are Buffers. The internal walker continues to operate on strings (latin1-encoded so each byte maps 1:1 to a code unit, preserving arbitrary bytes), and only the fs binding boundary and the result-emission boundary round-trip through Buffer; minimatch, path joining, and the seen-path cache are unchanged. Fixes: nodejs#59202 Signed-off-by: Maruthan G <[email protected]>
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.
fs: add encoding option to glob and globSync
fs.glob, fs.globSync, and fsPromises.glob always decoded
directory entries as UTF-8, so on POSIX any non-UTF-8 bytes in
file names were silently replaced with U+FFFD and the original
byte sequence could not be recovered.
Add an
encodingoption mirroring fs.readdir. When set to'buffer', glob returns Buffer paths and (when withFileTypes is
true) Dirents whose
nameandparentPathare Buffers. Theinternal walker continues to operate on strings (latin1-encoded
so each byte maps 1:1 to a code unit, preserving arbitrary
bytes), and only the fs binding boundary and the result-emission
boundary round-trip through Buffer; minimatch, path joining, and
the seen-path cache are unchanged.
Fixes: #59202
Note: I was unable to run the test suite locally (no built
out/Release/nodeon this Windows host; the system Node is v20 which predates fs.glob). Both touched JS files lint clean and passnode --check; doc edits follow existing fs.md patterns buttools/lint-mdis not installed locally. Looking forward to CI verification.