| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6e56924 commit 8009cb0
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. | |
@@ -591,21 +586,17 @@ then resolves the promise with no arguments upon success. | |||
| 591 | 586 | <!-- YAML | |
| 592 | 587 | added: v10.0.0 | |
| 593 | 588 | changes: | |
| 594 | - - version: v14.12.0 | ||
| 595 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 596 | - description: The `buffer` parameter will stringify an object with an | ||
| 597 | - explicit `toString` function. | ||
| 598 | 589 | - version: v14.0.0 | |
| 599 | 590 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 600 | 591 | description: The `buffer` parameter won't coerce unsupported input to | |
| 601 | 592 | buffers anymore. | |
| 602 | 593 | --> | |
| 603 | 594 | ||
| 604 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 595 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 605 | 596 | * `offset` {integer} The start position from within `buffer` where the data | |
| 606 | 597 | to write begins. **Default:** `0` | |
| 607 | 598 | * `length` {integer} The number of bytes from `buffer` to write. **Default:** | |
| 608 | - `buffer.byteLength` | ||
| 599 | + `buffer.byteLength - offset` | ||
| 609 | 600 | * `position` {integer} The offset from the beginning of the file where the | |
| 610 | 601 | data from `buffer` should be written. If `position` is not a `number`, | |
| 611 | 602 | the data will be written at the current position. See the POSIX pwrite(2) | |
@@ -614,13 +605,10 @@ changes: | |||
| 614 | 605 | ||
| 615 | 606 | Write `buffer` to the file. | |
| 616 | 607 | ||
| 617 | - If `buffer` is a plain object, it must have an own (not inherited) `toString` | ||
| 618 | - function property. | ||
| 619 | - | ||
| 620 | 608 | The promise is resolved with an object containing two properties: | |
| 621 | 609 | ||
| 622 | 610 | * `bytesWritten` {integer} the number of bytes written | |
| 623 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} a reference to the | ||
| 611 | + * `buffer` {Buffer|TypedArray|DataView} a reference to the | ||
| 624 | 612 | `buffer` written. | |
| 625 | 613 | ||
| 626 | 614 | It is unsafe to use `filehandle.write()` multiple times on the same file | |
@@ -636,31 +624,27 @@ the end of the file. | |||
| 636 | 624 | <!-- YAML | |
| 637 | 625 | added: v10.0.0 | |
| 638 | 626 | changes: | |
| 639 | - - version: v14.12.0 | ||
| 640 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 641 | - description: The `string` parameter will stringify an object with an | ||
| 642 | - explicit `toString` function. | ||
| 643 | 627 | - version: v14.0.0 | |
| 644 | 628 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 645 | 629 | description: The `string` parameter won't coerce unsupported input to | |
| 646 | 630 | strings anymore. | |
| 647 | 631 | --> | |
| 648 | 632 | ||
| 649 | - * `string` {string|Object} | ||
| 633 | + * `string` {string} | ||
| 650 | 634 | * `position` {integer} The offset from the beginning of the file where the | |
| 651 | 635 | data from `string` should be written. If `position` is not a `number` the | |
| 652 | 636 | data will be written at the current position. See the POSIX pwrite(2) | |
| 653 | 637 | documentation for more detail. | |
| 654 | 638 | * `encoding` {string} The expected string encoding. **Default:** `'utf8'` | |
| 655 | 639 | * Returns: {Promise} | |
| 656 | 640 | ||
| 657 | - Write `string` to the file. If `string` is not a string, or an object with an | ||
| 658 | - own `toString` function property, the promise is rejected with an error. | ||
| 641 | + Write `string` to the file. If `string` is not a string, the promise is | ||
| 642 | + rejected with an error. | ||
| 659 | 643 | ||
| 660 | 644 | The promise is resolved with an object containing two properties: | |
| 661 | 645 | ||
| 662 | 646 | * `bytesWritten` {integer} the number of bytes written | |
| 663 | - * `buffer` {string|Object} a reference to the `string` written. | ||
| 647 | + * `buffer` {string} a reference to the `string` written. | ||
| 664 | 648 | ||
| 665 | 649 | It is unsafe to use `filehandle.write()` multiple times on the same file | |
| 666 | 650 | without waiting for the promise to be resolved (or rejected). For this | |
@@ -680,27 +664,21 @@ changes: | |||
| 680 | 664 | - v14.18.0 | |
| 681 | 665 | pr-url: https://github.com/nodejs/node/pull/37490 | |
| 682 | 666 | description: The `data` argument supports `AsyncIterable`, `Iterable` and `Stream`. | |
| 683 | - - version: v14.12.0 | ||
| 684 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 685 | - description: The `data` parameter will stringify an object with an | ||
| 686 | - explicit `toString` function. | ||
| 687 | 667 | - version: v14.0.0 | |
| 688 | 668 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 689 | 669 | description: The `data` parameter won't coerce unsupported input to | |
| 690 | 670 | strings anymore. | |
| 691 | 671 | --> | |
| 692 | 672 | ||
| 693 | - * `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable | ||
| 694 | - |Stream} | ||
| 673 | + * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} | ||
| 695 | 674 | * `options` {Object|string} | |
| 696 | 675 | * `encoding` {string|null} The expected character encoding when `data` is a | |
| 697 | 676 | string. **Default:** `'utf8'` | |
| 698 | 677 | * Returns: {Promise} | |
| 699 | 678 | ||
| 700 | 679 | Asynchronously writes data to a file, replacing the file if it already exists. | |
| 701 | - `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object, or an | ||
| 702 | - object with an own `toString` function | ||
| 703 | - property. The promise is resolved with no arguments upon success. | ||
| 680 | + `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object. | ||
| 681 | + The promise is resolved with no arguments upon success. | ||
| 704 | 682 | ||
| 705 | 683 | If `options` is a string, then it specifies the `encoding`. | |
| 706 | 684 | ||
@@ -1536,19 +1514,14 @@ changes: | |||
| 1536 | 1514 | pr-url: https://github.com/nodejs/node/pull/35993 | |
| 1537 | 1515 | description: The options argument may include an AbortSignal to abort an | |
| 1538 | 1516 | ongoing writeFile request. | |
| 1539 | - - version: v14.12.0 | ||
| 1540 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 1541 | - description: The `data` parameter will stringify an object with an | ||
| 1542 | - explicit `toString` function. | ||
| 1543 | 1517 | - version: v14.0.0 | |
| 1544 | 1518 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 1545 | 1519 | description: The `data` parameter won't coerce unsupported input to | |
| 1546 | 1520 | strings anymore. | |
| 1547 | 1521 | --> | |
| 1548 | 1522 | ||
| 1549 | 1523 | * `file` {string|Buffer|URL|FileHandle} filename or `FileHandle` | |
| 1550 | - * `data` {string|Buffer|TypedArray|DataView|Object|AsyncIterable|Iterable | ||
| 1551 | - |Stream} | ||
| 1524 | + * `data` {string|Buffer|TypedArray|DataView|AsyncIterable|Iterable|Stream} | ||
| 1552 | 1525 | * `options` {Object|string} | |
| 1553 | 1526 | * `encoding` {string|null} **Default:** `'utf8'` | |
| 1554 | 1527 | * `mode` {integer} **Default:** `0o666` | |
@@ -1557,8 +1530,7 @@ changes: | |||
| 1557 | 1530 | * Returns: {Promise} Fulfills with `undefined` upon success. | |
| 1558 | 1531 | ||
| 1559 | 1532 | Asynchronously writes data to a file, replacing the file if it already exists. | |
| 1560 | - `data` can be a string, a {Buffer}, or, an object with an own (not inherited) | ||
| 1561 | - `toString` function property. | ||
| 1533 | + `data` can be a string, a buffer, an {AsyncIterable} or {Iterable} object. | ||
| 1562 | 1534 | ||
| 1563 | 1535 | The `encoding` option is ignored if `data` is a buffer. | |
| 1564 | 1536 | ||
@@ -4161,10 +4133,6 @@ This happens when: | |||
| 4161 | 4133 | <!-- YAML | |
| 4162 | 4134 | added: v0.0.2 | |
| 4163 | 4135 | changes: | |
| 4164 | - - version: v14.12.0 | ||
| 4165 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 4166 | - description: The `buffer` parameter will stringify an object with an | ||
| 4167 | - explicit `toString` function. | ||
| 4168 | 4136 | - version: v14.0.0 | |
| 4169 | 4137 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 4170 | 4138 | description: The `buffer` parameter won't coerce unsupported input to | |
@@ -4190,7 +4158,7 @@ changes: | |||
| 4190 | 4158 | --> | |
| 4191 | 4159 | ||
| 4192 | 4160 | * `fd` {integer} | |
| 4193 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 4161 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 4194 | 4162 | * `offset` {integer} | |
| 4195 | 4163 | * `length` {integer} | |
| 4196 | 4164 | * `position` {integer} | |
@@ -4199,8 +4167,7 @@ changes: | |||
| 4199 | 4167 | * `bytesWritten` {integer} | |
| 4200 | 4168 | * `buffer` {Buffer|TypedArray|DataView} | |
| 4201 | 4169 | ||
| 4202 | - Write `buffer` to the file specified by `fd`. If `buffer` is a normal object, it | ||
| 4203 | - must have an own `toString` function property. | ||
| 4170 | + Write `buffer` to the file specified by `fd`. | ||
| 4204 | 4171 | ||
| 4205 | 4172 | `offset` determines the part of the buffer to be written, and `length` is | |
| 4206 | 4173 | an integer specifying the number of bytes to write. | |
@@ -5557,10 +5524,6 @@ this API: [`fs.writeFile()`][]. | |||
| 5557 | 5524 | <!-- YAML | |
| 5558 | 5525 | added: v0.1.21 | |
| 5559 | 5526 | changes: | |
| 5560 | - - version: v14.12.0 | ||
| 5561 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 5562 | - description: The `buffer` parameter will stringify an object with an | ||
| 5563 | - explicit `toString` function. | ||
| 5564 | 5527 | - version: v14.0.0 | |
| 5565 | 5528 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 5566 | 5529 | description: The `buffer` parameter won't coerce unsupported input to | |
@@ -5578,15 +5541,12 @@ changes: | |||
| 5578 | 5541 | --> | |
| 5579 | 5542 | ||
| 5580 | 5543 | * `fd` {integer} | |
| 5581 | - * `buffer` {Buffer|TypedArray|DataView|string|Object} | ||
| 5544 | + * `buffer` {Buffer|TypedArray|DataView} | ||
| 5582 | 5545 | * `offset` {integer} | |
| 5583 | 5546 | * `length` {integer} | |
| 5584 | 5547 | * `position` {integer} | |
| 5585 | 5548 | * Returns: {number} The number of bytes written. | |
| 5586 | 5549 | ||
| 5587 | - If `buffer` is a plain object, it must have an own (not inherited) `toString` | ||
| 5588 | - function property. | ||
| 5589 | - | ||
| 5590 | 5550 | For detailed information, see the documentation of the asynchronous version of | |
| 5591 | 5551 | this API: [`fs.write(fd, buffer...)`][]. | |
| 5592 | 5552 | ||
@@ -5595,10 +5555,6 @@ this API: [`fs.write(fd, buffer...)`][]. | |||
| 5595 | 5555 | <!-- YAML | |
| 5596 | 5556 | added: v0.11.5 | |
| 5597 | 5557 | changes: | |
| 5598 | - - version: v14.12.0 | ||
| 5599 | - pr-url: https://github.com/nodejs/node/pull/34993 | ||
| 5600 | - description: The `string` parameter will stringify an object with an | ||
| 5601 | - explicit `toString` function. | ||
| 5602 | 5558 | - version: v14.0.0 | |
| 5603 | 5559 | pr-url: https://github.com/nodejs/node/pull/31030 | |
| 5604 | 5560 | description: The `string` parameter won't coerce unsupported input to | |
@@ -5609,14 +5565,11 @@ changes: | |||
| 5609 | 5565 | --> | |
| 5610 | 5566 | ||
| 5611 | 5567 | * `fd` {integer} | |
| 5612 | - * `string` {string|Object} | ||
| 5568 | + * `string` {string} | ||
| 5613 | 5569 | * `position` {integer} | |
| 5614 | 5570 | * `encoding` {string} | |
| 5615 | 5571 | * Returns: {number} The number of bytes written. | |
| 5616 | 5572 | ||
| 5617 | - If `string` is a plain object, it must have an own (not inherited) `toString` | ||
| 5618 | - function property. | ||
| 5619 | - | ||
| 5620 | 5573 | For detailed information, see the documentation of the asynchronous version of | |
| 5621 | 5574 | this API: [`fs.write(fd, string...)`][]. | |
| 5622 | 5575 | ||
| 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 | |
|---|---|---|---|
@@ -65,7 +65,7 @@ const { | |||
| 65 | 65 | validateOffsetLengthWrite, | |
| 66 | 66 | validateRmOptions, | |
| 67 | 67 | validateRmdirOptions, | |
| 68 | - validateStringAfterArrayBufferView, | ||
| 68 | + validatePrimitiveStringAfterArrayBufferView, | ||
| 69 | 69 | warnOnNonPortableTemplate, | |
| 70 | 70 | } = require('internal/fs/utils'); | |
| 71 | 71 | const { opendir } = require('internal/fs/dir'); | |
@@ -581,7 +581,7 @@ async function write(handle, buffer, offset, length, position) { | |||
| 581 | 581 | return { bytesWritten, buffer }; | |
| 582 | 582 | } | |
| 583 | 583 | ||
| 584 | - validateStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 584 | + validatePrimitiveStringAfterArrayBufferView(buffer, 'buffer'); | ||
| 585 | 585 | validateEncoding(buffer, length); | |
| 586 | 586 | const bytesWritten = (await binding.writeString(handle.fd, buffer, offset, | |
| 587 | 587 | length, kUsePromises)) || 0; | |
@@ -811,7 +811,7 @@ async function writeFile(path, data, options) { | |||
| 811 | 811 | const flag = options.flag || 'w'; | |
| 812 | 812 | ||
| 813 | 813 | if (!isArrayBufferView(data) && !isCustomIterable(data)) { | |
| 814 | - validateStringAfterArrayBufferView(data, 'data'); | ||
| 814 | + validatePrimitiveStringAfterArrayBufferView(data, 'data'); | ||
| 815 | 815 | data = Buffer.from(data, options.encoding || 'utf8'); | |
| 816 | 816 | } | |
| 817 | 817 | ||
| 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