Skip to content

fs: validate falsy openAsBlob type option - #66125

Open
christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:fs-openasblob-type-validation
Open

christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:fs-openasblob-type-validation

Conversation

@christianaurichzm

Copy link
Copy Markdown
Contributor

openAsBlob() and openAsBlobSync() use options.type || '' before validating the option. This causes falsy non-string values such as null, false, 0, and NaN to be silently replaced with the default empty string instead of throwing ERR_INVALID_ARG_TYPE.

This changes the defaulting behavior so only undefined uses the empty string default. All other values are passed to validateString().

Tests were added for the affected falsy non-string values.

openAsBlob() and openAsBlobSync() read the MIME type as
options.type || '' before validating it, causing falsy non-string
values to be replaced with the default before reaching validateString().
As a result, { type: 0 }, { type: false }, { type: null }, and
{ type: NaN } are accepted as an empty type, while { type: 1 }
throws ERR_INVALID_ARG_TYPE.

Default the option only when it is undefined so all other values are
validated against the documented string type.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
@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 Sep 19, 2026
@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (b125121) to head (0545339).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66125      +/-   ##
==========================================
- Coverage   90.29%   90.29%   -0.01%     
==========================================
  Files         790      790              
  Lines      271689   271784      +95     
  Branches    51856    51877      +21     
==========================================
+ Hits       245312   245395      +83     
- Misses      16878    16888      +10     
- Partials     9499     9501       +2     
Files with missing lines Coverage Δ
lib/fs.js 97.32% <100.00%> (ø)

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Development

Successfully merging this pull request may close these issues.

3 participants