GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: accept uppercase UTF8 encoding in fast paths by AliMahmoudDev · Pull Request #63576 · nodejs/node

Conversation

@AliMahmoudDev

@AliMahmoudDev AliMahmoudDev commented May 26, 2026

Copy link
Copy Markdown

Summary

Fixes #49888

The and UTF8 fast paths (introduced in #48658 and #49884) only accepted lowercase encoding strings 'utf8' and 'utf-8'. The uppercase variants 'UTF8' and 'UTF-8' are valid encodings (accepted by Buffer.isEncoding()) but were not routed to the fast path, causing them to fall through to the slower generic code path.

Changes

  • lib/fs.js: Extended the fast path checks in readFileSync and writeFileSync to also accept 'UTF8' and 'UTF-8'
  • Added test file test/parallel/test-fs-utf8-fast-path-encoding.js verifying all four encoding variants work correctly with both string and object form options

Testing

New test covers:

  • writeFileSync(path, data, encoding) — string form
  • readFileSync(path, encoding) — string form
  • readFileSync(path, { encoding }) — object form
  • writeFileSync(path, data, { encoding }) — object form

All four encoding variants ('utf8', 'utf-8', 'UTF8', 'UTF-8') are tested with Unicode characters (CJK, emoji) to verify correctness.

node test/parallel/test-fs-utf8-fast-path-encoding.js

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AliMahmoudDev
fs: accept uppercase UTF8 encoding in fast paths
3e66959
The readFileSync and writeFileSync UTF8 fast paths only accepted
lowercase 'utf8' and 'utf-8' encodings. Accept 'UTF8' and 'UTF-8'
as well, since they are valid encoding aliases per Buffer.isEncoding().

Refs: nodejs#49888
@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels May 26, 2026
addaleax
addaleax reviewed May 26, 2026
View reviewed changes

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

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.

It might be fine to leave this as-is, since utf-8 and utf8 are the most commonly used labels and fast paths inherently focus on common cases, and the extra comparisons aren't completely free either

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AliMahmoudDev AliMahmoudDev closed this May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

fs Issues and PRs related to file-system APIs and the fs module. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fs: utf8 fast paths don't accept all valid utf8 values

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@AliMahmoudDev @addaleax @nodejs-github-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.