Skip to content

Commit 720ef24

Browse files
committed
squash: harden string validation in fh.writeFile and fh.appendFile
1 parent b3d04aa commit 720ef24

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

doc/api/fs.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,10 @@ the end of the file.
695695
<!-- YAML
696696
added: v10.0.0
697697
changes:
698+
- version: REPLACEME
699+
pr-url: https://github.com/nodejs/node/pull/41677
700+
description: The `data` parameter no longer accepts objects with an
701+
own `toString` function property.
698702
- version:
699703
- v15.14.0
700704
- v14.18.0
@@ -710,17 +714,15 @@ changes:
710714
strings anymore.
711715
-->
712716
713-
* `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable
714-
|Stream}
717+
* `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream}
715718
* `options` {Object|string}
716719
* `encoding` {string|null} The expected character encoding when `data` is a
717720
string. **Default:** `'utf8'`
718721
* Returns: {Promise}
719722
720723
Asynchronously writes data to a file, replacing the file if it already exists.
721-
`data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object, or an
722-
object with an own `toString` function
723-
property. The promise is resolved with no arguments upon success.
724+
`data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object.
725+
The promise is resolved with no arguments upon success.
724726
725727
If `options` is a string, then it specifies the `encoding`.
726728

lib/internal/fs/promises.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const {
6565
validateOffsetLengthWrite,
6666
validateRmOptions,
6767
validateRmdirOptions,
68-
validateStringAfterArrayBufferView,
6968
validatePrimitiveStringAfterArrayBufferView,
7069
warnOnNonPortableTemplate,
7170
} = require('internal/fs/utils');
@@ -823,7 +822,7 @@ async function writeFile(path, data, options) {
823822
const flag = options.flag || 'w';
824823

825824
if (!isArrayBufferView(data) && !isCustomIterable(data)) {
826-
validateStringAfterArrayBufferView(data, 'data');
825+
validatePrimitiveStringAfterArrayBufferView(data, 'data');
827826
data = Buffer.from(data, options.encoding || 'utf8');
828827
}
829828

0 commit comments

Comments
 (0)