fs: accept all valid utf8 values in fast paths - #62304
Conversation
Accept UTF8 and UTF-8 (uppercase) in fs.readFileSync and fs.writeFileSync fast paths, in addition to utf8 and utf-8. Fixes: nodejs#49888
jasnell
left a comment
There was a problem hiding this comment.
LGTM modulo the linting issues in the test
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62304 +/- ##
=======================================
Coverage 89.68% 89.68%
=======================================
Files 676 676
Lines 206575 206577 +2
Branches 39549 39553 +4
=======================================
+ Hits 185262 185274 +12
+ Misses 13446 13445 -1
+ Partials 7867 7858 -9
🚀 New features to boost your workflow:
|
The fs.readFileSync and fs.writeFileSync fast paths for UTF-8 encoding only accepted exact matches: 'utf8', 'utf-8', 'UTF8', 'UTF-8'. However, Node.js considers all case-insensitive variations as valid UTF-8 (e.g., 'Utf8', 'Utf-8', 'uTf8', etc.). This commit adds an isUtf8Encoding() helper function that accepts all valid UTF-8 encoding names, matching the behavior of normalizeEncoding() in lib/internal/util.js. Fixes nodejs#49888
|
This pull request has been marked as stale due to 90 days of inactivity. |
|
This pull request has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days). |
This PR fixes issue #49888 by accepting all valid UTF8 encoding variants (utf8, utf-8, UTF8, UTF-8) in fs.readFileSync and fs.writeFileSync fast paths.
Changes
Testing
Fixes: #49888