diff options
author | Livia Medeiros <74449973+LiviaMedeiros@users.noreply.github.com> | 2022-04-08 13:16:08 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-08 13:16:08 +0300 |
commit | 0bac5478eb9d242719f7e19f44db03d36c3647d8 (patch) | |
tree | 8240da4008c1aadec639c4d5999886a56844d3ba /lib | |
parent | c08a361f706e60db9a2718282ea12abc1b04b882 (diff) |
fs: runtime deprecate string coercion in `fs.write`, `fs.writeFileSync`
This also affects `fs.writeFile`, `fs.appendFile`, and
`fs.appendFileSync`
PR-URL: https://github.com/nodejs/node/pull/42607
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/fs.js b/lib/fs.js index 417fff0dedc..405c206d566 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -163,6 +163,11 @@ const isWindows = process.platform === 'win32'; const isOSX = process.platform === 'darwin'; +const showStringCoercionDeprecation = internalUtil.deprecate( + () => {}, + 'Implicit coercion of objects with own toString property is deprecated.', + 'DEP0162' +); function showTruncateDeprecation() { if (truncateWarn) { process.emitWarning( @@ -826,6 +831,9 @@ function write(fd, buffer, offset, length, position, callback) { } validateStringAfterArrayBufferView(buffer, 'buffer'); + if (typeof buffer !== 'string') { + showStringCoercionDeprecation(); + } if (typeof position !== 'function') { if (typeof offset === 'function') { @@ -2121,6 +2129,9 @@ function writeFile(path, data, options, callback) { if (!isArrayBufferView(data)) { validateStringAfterArrayBufferView(data, 'data'); + if (typeof data !== 'string') { + showStringCoercionDeprecation(); + } data = Buffer.from(String(data), options.encoding || 'utf8'); } @@ -2161,6 +2172,9 @@ function writeFileSync(path, data, options) { if (!isArrayBufferView(data)) { validateStringAfterArrayBufferView(data, 'data'); + if (typeof data !== 'string') { + showStringCoercionDeprecation(); + } data = Buffer.from(String(data), options.encoding || 'utf8'); } |