Repository navigation
Conversation
Add an `encoding` option to `fs.glob()`, `fs.globSync()`, and `fs.promises.glob()`. The glob walker already operates on raw path bytes; encode results at the native-to-JavaScript boundary instead so that filenames which are not valid UTF-8 can be returned without loss when `encoding` is `'buffer'`. With `withFileTypes`, the `name` and `parentPath` properties of each Dirent, as well as the values passed to `exclude` callbacks, use the requested encoding. Filesystem operations, including the lstat used for path callbacks, keep using the original paths. The default encoding remains `'utf8'`. Refs: nodejs#59202 Signed-off-by: XadillaX <i@2333.moe> Assisted-by: Trae
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66856 +/- ##
=======================================
Coverage 90.50% 90.50%
=======================================
Files 797 797
Lines 278196 278269 +73
Branches 53453 53470 +17
=======================================
+ Hits 251772 251850 +78
+ Misses 16797 16787 -10
- Partials 9627 9632 +5
🚀 New features to boost your workflow:
|
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.
Summary
fs.glob(),fs.globSync(), andfs.promises.glob()always decodedresults as UTF-8. On a filename that is not valid UTF-8, the bytes were
lost at the native-to-JavaScript boundary and could not be recovered
with
Buffer.from(), even though the rest offssupports Buffer paths.encodingoption (default'utf8'). With'buffer', matchedpaths are returned as
Bufferobjects preserving the raw filenamebytes.
withFileTypes, the Direntname/parentPathand the valuespassed to
excludecallbacks use the requested encoding.callbacks) keep operating on the original raw paths; encoding is
applied only when crossing into JavaScript.
encodingand document the option for all three APIs.Tests
test/parallel/test-fs-glob-encoding.mjscovering all threeentry points across encodings, Dirent fields,
excludecallbacks,relative/root
cwd, iterator batching, and (on Linux) filenamescontaining raw non-UTF-8 bytes including read-back through the
returned Buffer paths.
path.glob, glob syntax, permission, and watch-ignoresuites remain green.
Fixes: #59202