| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a2e858f commit a45aabe
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,18 +185,13 @@ changes: | |||
| 185 | 185 | - v14.18.0 | |
| 186 | 186 | pr-url: https://github.com/nodejs/node/pull/37490 | |
| 187 | 187 | description: The `data` argument supports `AsyncIterable`, `Iterable` and `Stream`. | |
| 188 | - - version: v14.12.0 | ||
| 189 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 190 | - description: The `data` parameter will stringify an object with an | ||
| 191 | - explicit `toString` function. | ||
| 192 | 188 | - version: v14.0.0 | |
| 193 | 189 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 194 | 190 | description: The `data` parameter won't coerce unsupported input to | |
| 195 | 191 | strings anymore. | |
| 196 | 192 | --> | |
| 197 | 193 | ||
| 198 | - * `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable | ||
| 199 | - |Stream} | ||
| 194 | + * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} | ||
| 200 | 195 | * `options` {Object|string} | |
| 201 | 196 | * `encoding` {string|null} **Default:** `'utf8'` | |
| 202 | 197 | * Returns: {Promise} Fulfills with `undefined` upon success. | |
@@ -544,21 +539,17 @@ then resolves the promise with no arguments upon success. | |||
| 544 | 539 | <!-- YAML | |
| 545 | 540 | added: v10.0.0 | |
| 546 | 541 | changes: | |
| 547 | - - version: v14.12.0 | ||
| 548 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 549 | - description: The `buffer` parameter will stringify an object with an | ||
| 550 | - explicit `toString` function. | ||
| 551 | 542 | - version: v14.0.0 | |
| 552 | 543 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 553 | 544 | description: The `buffer` parameter won't coerce unsupported input to | |
| 554 | 545 | buffers anymore. | |
| 555 | 546 | --> | |
| 556 | 547 | ||
| 557 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 548 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 558 | 549 | * `offset` {integer} The start position from within `buffer` where the data | |
| 559 | 550 | to write begins. **Default:** `0` | |
| 560 | 551 | * `length` {integer} The number of bytes from `buffer` to write. **Default:** | |
| 561 | - `buffer.byteLength` | ||
| 552 | + `buffer.byteLength - offset` | ||
| 562 | 553 | * `position` {integer} The offset from the beginning of the file where the | |
| 563 | 554 | data from `buffer` should be written. If `position` is not a `number`, | |
| 564 | 555 | the data will be written at the current position. See the POSIX pwrite(2) | |
@@ -567,13 +558,10 @@ changes: | |||
| 567 | 558 | ||
| 568 | 559 | Write `buffer` to the file. | |
| 569 | 560 | ||
| 570 | - If `buffer` is a plain object, it must have an own (not inherited) `toString` | ||
| 571 | - function property. | ||
| 572 | - | ||
| 573 | 561 | The promise is resolved with an object containing two properties: | |
| 574 | 562 | ||
| 575 | 563 | * `bytesWritten` {integer} the number of bytes written | |
| 576 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} a reference to the | ||
| 564 | + * `buffer` {Buffer|TypedArray|DataView} a reference to the | ||
| 577 | 565 | `buffer` written. | |
| 578 | 566 | ||
| 579 | 567 | It is unsafe to use `filehandle.write()` multiple times on the same file | |
@@ -589,31 +577,27 @@ the end of the file. | |||
| 589 | 577 | <!-- YAML | |
| 590 | 578 | added: v10.0.0 | |
| 591 | 579 | changes: | |
| 592 | - - version: v14.12.0 | ||
| 593 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 594 | - description: The `string` parameter will stringify an object with an | ||
| 595 | - explicit `toString` function. | ||
| 596 | 580 | - version: v14.0.0 | |
| 597 | 581 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 598 | 582 | description: The `string` parameter won't coerce unsupported input to | |
| 599 | 583 | strings anymore. | |
| 600 | 584 | --> | |
| 601 | 585 | ||
| 602 | - * `string` {string|Object} | ||
| 586 | + * `string` {string} | ||
| 603 | 587 | * `position` {integer} The offset from the beginning of the file where the | |
| 604 | 588 | data from `string` should be written. If `position` is not a `number` the | |
| 605 | 589 | data will be written at the current position. See the POSIX pwrite(2) | |
| 606 | 590 | documentation for more detail. | |
| 607 | 591 | * `encoding` {string} The expected string encoding. **Default:** `'utf8'` | |
| 608 | 592 | * Returns: {Promise} | |
| 609 | 593 | ||
| 610 | - Write `string` to the file. If `string` is not a string, or an object with an | ||
| 611 | - own `toString` function property, the promise is rejected with an error. | ||
| 594 | + Write `string` to the file. If `string` is not a string, the promise is | ||
| 595 | + rejected with an error. | ||
| 612 | 596 | ||
| 613 | 597 | The promise is resolved with an object containing two properties: | |
| 614 | 598 | ||
| 615 | 599 | * `bytesWritten` {integer} the number of bytes written | |
| 616 | - * `buffer` {string|Object} a reference to the `string` written. | ||
| 600 | + * `buffer` {string} a reference to the `string` written. | ||
| 617 | 601 | ||
| 618 | 602 | It is unsafe to use `filehandle.write()` multiple times on the same file | |
| 619 | 603 | without waiting for the promise to be resolved (or rejected). For this | |
@@ -631,27 +615,21 @@ changes: | |||
| 631 | 615 | - version: v15.14.0 | |
| 632 | 616 | pr-url: https://github.com/nodejs/node/pull/37490 | |
| 633 | 617 | description: The `data` argument supports `AsyncIterable`, `Iterable` and `Stream`. | |
| 634 | - - version: v14.12.0 | ||
| 635 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 636 | - description: The `data` parameter will stringify an object with an | ||
| 637 | - explicit `toString` function. | ||
| 638 | 618 | - version: v14.0.0 | |
| 639 | 619 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 640 | 620 | description: The `data` parameter won't coerce unsupported input to | |
| 641 | 621 | strings anymore. | |
| 642 | 622 | --> | |
| 643 | 623 | ||
| 644 | - * `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable | ||
| 645 | - |Stream} | ||
| 624 | + * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} | ||
| 646 | 625 | * `options` {Object|string} | |
| 647 | 626 | * `encoding` {string|null} The expected character encoding when `data` is a | |
| 648 | 627 | string. **Default:** `'utf8'` | |
| 649 | 628 | * Returns: {Promise} | |
| 650 | 629 | ||
| 651 | 630 | Asynchronously writes data to a file, replacing the file if it already exists. | |
| 652 | - `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object, or an | ||
| 653 | - object with an own `toString` function | ||
| 654 | - property. The promise is resolved with no arguments upon success. | ||
| 631 | + `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object. | ||
| 632 | + The promise is resolved with no arguments upon success. | ||
| 655 | 633 | ||
| 656 | 634 | If `options` is a string, then it specifies the `encoding`. | |
| 657 | 635 | ||
@@ -1481,19 +1459,14 @@ changes: | |||
| 1481 | 1459 | pr-url: https://github.com/nodejs/node/pull/35993 | |
| 1482 | 1460 | description: The options argument may include an AbortSignal to abort an | |
| 1483 | 1461 | ongoing writeFile request. | |
| 1484 | - - version: v14.12.0 | ||
| 1485 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 1486 | - description: The `data` parameter will stringify an object with an | ||
| 1487 | - explicit `toString` function. | ||
| 1488 | 1462 | - version: v14.0.0 | |
| 1489 | 1463 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 1490 | 1464 | description: The `data` parameter won't coerce unsupported input to | |
| 1491 | 1465 | strings anymore. | |
| 1492 | 1466 | --> | |
| 1493 | 1467 | ||
| 1494 | 1468 | * `file` {string|Buffer|URL|FileHandle} filename or `FileHandle` | |
| 1495 | - * `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable | ||
| 1496 | - |Stream} | ||
| 1469 | + * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} | ||
| 1497 | 1470 | * `options` {Object|string} | |
| 1498 | 1471 | * `encoding` {string|null} **Default:** `'utf8'` | |
| 1499 | 1472 | * `mode` {integer} **Default:** `0o666` | |
@@ -1502,8 +1475,7 @@ changes: | |||
| 1502 | 1475 | * Returns: {Promise} Fulfills with `undefined` upon success. | |
| 1503 | 1476 | ||
| 1504 | 1477 | Asynchronously writes data to a file, replacing the file if it already exists. | |
| 1505 | - `data` can be a string, a {Buffer}, or, an object with an own (not inherited) | ||
| 1506 | - `toString` function property. | ||
| 1478 | + `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object. | ||
| 1507 | 1479 | ||
| 1508 | 1480 | The `encoding` option is ignored if `data` is a buffer. | |
| 1509 | 1481 | ||
@@ -4098,10 +4070,6 @@ This happens when: | |||
| 4098 | 4070 | <!-- YAML | |
| 4099 | 4071 | added: v0.0.2 | |
| 4100 | 4072 | changes: | |
| 4101 | - - version: v14.12.0 | ||
| 4102 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 4103 | - description: The `buffer` parameter will stringify an object with an | ||
| 4104 | - explicit `toString` function. | ||
| 4105 | 4073 | - version: v14.0.0 | |
| 4106 | 4074 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 4107 | 4075 | description: The `buffer` parameter won't coerce unsupported input to | |
@@ -4127,7 +4095,7 @@ changes: | |||
| 4127 | 4095 | --> | |
| 4128 | 4096 | ||
| 4129 | 4097 | * `fd` {integer} | |
| 4130 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 4098 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 4131 | 4099 | * `offset` {integer} | |
| 4132 | 4100 | * `length` {integer} | |
| 4133 | 4101 | * `position` {integer} | |
@@ -4136,8 +4104,7 @@ changes: | |||
| 4136 | 4104 | * `bytesWritten` {integer} | |
| 4137 | 4105 | * `buffer` {Buffer|TypedArray|DataView} | |
| 4138 | 4106 | ||
| 4139 | - Write `buffer` to the file specified by `fd`. If `buffer` is a normal object, it | ||
| 4140 | - must have an own `toString` function property. | ||
| 4107 | + Write `buffer` to the file specified by `fd`. | ||
| 4141 | 4108 | ||
| 4142 | 4109 | `offset` determines the part of the buffer to be written, and `length` is | |
| 4143 | 4110 | an integer specifying the number of bytes to write. | |
@@ -5490,10 +5457,6 @@ this API: [`fs.writeFile()`][]. | |||
| 5490 | 5457 | <!-- YAML | |
| 5491 | 5458 | added: v0.1.21 | |
| 5492 | 5459 | changes: | |
| 5493 | - - version: v14.12.0 | ||
| 5494 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 5495 | - description: The `buffer` parameter will stringify an object with an | ||
| 5496 | - explicit `toString` function. | ||
| 5497 | 5460 | - version: v14.0.0 | |
| 5498 | 5461 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 5499 | 5462 | description: The `buffer` parameter won't coerce unsupported input to | |
@@ -5511,15 +5474,12 @@ changes: | |||
| 5511 | 5474 | --> | |
| 5512 | 5475 | ||
| 5513 | 5476 | * `fd` {integer} | |
| 5514 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 5477 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 5515 | 5478 | * `offset` {integer} | |
| 5516 | 5479 | * `length` {integer} | |
| 5517 | 5480 | * `position` {integer} | |
| 5518 | 5481 | * Returns: {number} The number of bytes written. | |
| 5519 | 5482 | ||
| 5520 | - If `buffer` is a plain object, it must have an own (not inherited) `toString` | ||
| 5521 | - function property. | ||
| 5522 | - | ||
| 5523 | 5483 | For detailed information, see the documentation of the asynchronous version of | |
| 5524 | 5484 | this API: [`fs.write(fd, buffer...)`][]. | |
| 5525 | 5485 | ||
@@ -5528,10 +5488,6 @@ this API: [`fs.write(fd, buffer...)`][]. | |||
| 5528 | 5488 | <!-- YAML | |
| 5529 | 5489 | added: v0.11.5 | |
| 5530 | 5490 | changes: | |
| 5531 | - - version: v14.12.0 | ||
| 5532 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 5533 | - description: The `string` parameter will stringify an object with an | ||
| 5534 | - explicit `toString` function. | ||
| 5535 | 5491 | - version: v14.0.0 | |
| 5536 | 5492 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 5537 | 5493 | description: The `string` parameter won't coerce unsupported input to | |
@@ -5542,14 +5498,11 @@ changes: | |||
| 5542 | 5498 | --> | |
| 5543 | 5499 | ||
| 5544 | 5500 | * `fd` {integer} | |
| 5545 | - * `string` {string|Object} | ||
| 5501 | + * `string` {string} | ||
| 5546 | 5502 | * `position` {integer} | |
| 5547 | 5503 | * `encoding` {string} | |
| 5548 | 5504 | * Returns: {number} The number of bytes written. | |
| 5549 | 5505 | ||
| 5550 | - If `string` is a plain object, it must have an own (not inherited) `toString` | ||
| 5551 | - function property. | ||
| 5552 | - | ||
| 5553 | 5506 | For detailed information, see the documentation of the asynchronous version of | |
| 5554 | 5507 | this API: [`fs.write(fd, string...)`][]. | |
| 5555 | 5508 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,7 @@ const { | |||
| 116 | 116 | validateRmOptionsSync, | |
| 117 | 117 | validateRmdirOptions, | |
| 118 | 118 | validateStringAfterArrayBufferView, | |
| 119 | + validatePrimitiveStringAfterArrayBufferView, | ||
| 119 | 120 | warnOnNonPortableTemplate | |
| 120 | 121 | } = require('internal/fs/utils'); | |
| 121 | 122 | const { | |
@@ -853,7 +854,7 @@ ObjectDefineProperty(write, internalUtil.customPromisifyArgs, | |||
| 853 | 854 | * Synchronously writes `buffer` to the | |
| 854 | 855 | * specified `fd` (file descriptor). | |
| 855 | 856 | * @param {number} fd | |
| 856 | - * @param {Buffer | TypedArray | DataView | string | object} buffer | ||
| 857 | + * @param {Buffer | TypedArray | DataView | string} buffer | ||
| 857 | 858 | * @param {number} [offset] | |
| 858 | 859 | * @param {number} [length] | |
| 859 | 860 | * @param {number} [position] | |
@@ -877,7 +878,7 @@ function writeSync(fd, buffer, offset, length, position) { | |||
| 877 | 878 | result = binding.writeBuffer(fd, buffer, offset, length, position, | |
| 878 | 879 | undefined, ctx); | |
| 879 | 880 | } else { | |
| 880 | - validateStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 881 | + validatePrimitiveStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 881 | 882 | validateEncoding(buffer, length); | |
| 882 | 883 | ||
| 883 | 884 | if (offset === undefined) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,7 +62,7 @@ const { | |||
| 62 | 62 | validateOffsetLengthWrite, | |
| 63 | 63 | validateRmOptions, | |
| 64 | 64 | validateRmdirOptions, | |
| 65 | - validateStringAfterArrayBufferView, | ||
| 65 | + validatePrimitiveStringAfterArrayBufferView, | ||
| 66 | 66 | warnOnNonPortableTemplate, | |
| 67 | 67 | } = require('internal/fs/utils'); | |
| 68 | 68 | const { opendir } = require('internal/fs/dir'); | |
@@ -529,7 +529,7 @@ async function write(handle, buffer, offset, length, position) { | |||
| 529 | 529 | return { bytesWritten, buffer }; | |
| 530 | 530 | } | |
| 531 | 531 | ||
| 532 | - validateStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 532 | + validatePrimitiveStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 533 | 533 | validateEncoding(buffer, length); | |
| 534 | 534 | const bytesWritten = (await binding.writeString(handle.fd, buffer, offset, | |
| 535 | 535 | length, kUsePromises)) || 0; | |
@@ -759,7 +759,7 @@ async function writeFile(path, data, options) { | |||
| 759 | 759 | const flag = options.flag || 'w'; | |
| 760 | 760 | ||
| 761 | 761 | if (!isArrayBufferView(data) && !isCustomIterable(data)) { | |
| 762 | - validateStringAfterArrayBufferView(data, 'data'); | ||
| 762 | + validatePrimitiveStringAfterArrayBufferView(data, 'data'); | ||
| 763 | 763 | data = Buffer.from(data, options.encoding || 'utf8'); | |
| 764 | 764 | } | |
| 765 | 765 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -889,6 +889,16 @@ const validateStringAfterArrayBufferView = hideStackFrames((buffer, name) => { | |||
| 889 | 889 | ); | |
| 890 | 890 | }); | |
| 891 | 891 | ||
| 892 | + const validatePrimitiveStringAfterArrayBufferView = hideStackFrames((buffer, name) => { | ||
| 893 | + if (typeof buffer !== 'string') { | ||
| 894 | + throw new ERR_INVALID_ARG_TYPE( | ||
| 895 | + name, | ||
| 896 | + ['string', 'Buffer', 'TypedArray', 'DataView'], | ||
| 897 | + buffer | ||
| 898 | + ); | ||
| 899 | + } | ||
| 900 | + }); | ||
| 901 | + | ||
| 892 | 902 | const validatePosition = hideStackFrames((position, name) => { | |
| 893 | 903 | if (typeof position === 'number') { | |
| 894 | 904 | validateInteger(position, 'position'); | |
@@ -943,5 +953,6 @@ module.exports = { | |||
| 943 | 953 | validateRmOptionsSync, | |
| 944 | 954 | validateRmdirOptions, | |
| 945 | 955 | validateStringAfterArrayBufferView, | |
| 956 | + validatePrimitiveStringAfterArrayBufferView, | ||
| 946 | 957 | warnOnNonPortableTemplate | |
| 947 | 958 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,12 @@ async function validateNonUint8ArrayWrite() { | |||
| 53 | 53 | async function validateNonStringValuesWrite() { | |
| 54 | 54 | const filePathForHandle = path.resolve(tmpDir, 'tmp-non-string-write.txt'); | |
| 55 | 55 | const fileHandle = await open(filePathForHandle, 'w+'); | |
| 56 | - const nonStringValues = [123, {}, new Map(), null, undefined, 0n, () => {}, Symbol(), true]; | ||
| 56 | + const nonStringValues = [ | ||
| 57 | + 123, {}, new Map(), null, undefined, 0n, () => {}, Symbol(), true, | ||
| 58 | + new String('notPrimitive'), | ||
| 59 | + { toString() { return 'amObject'; } }, | ||
| 60 | + { [Symbol.toPrimitive]: (hint) => 'amObject' }, | ||
| 61 | + ]; | ||
| 57 | 62 | for (const nonStringValue of nonStringValues) { | |
| 58 | 63 | await assert.rejects( | |
| 59 | 64 | fileHandle.write(nonStringValue), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -155,7 +155,11 @@ fs.open(fn4, 'w', 0o644, common.mustSucceed((fd) => { | |||
| 155 | 155 | ); | |
| 156 | 156 | }); | |
| 157 | 157 | ||
| 158 | - [false, 5, {}, [], null, undefined].forEach((data) => { | ||
| 158 | + [ | ||
| 159 | + false, 5, {}, [], null, undefined, | ||
| 160 | + new String('notPrimitive'), | ||
| 161 | + { [Symbol.toPrimitive]: (hint) => 'amObject' }, | ||
| 162 | + ].forEach((data) => { | ||
| 159 | 163 | assert.throws( | |
| 160 | 164 | () => fs.write(1, data, common.mustNotCall()), | |
| 161 | 165 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments