| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e6e1f4e commit ac178b0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1040,7 +1040,7 @@ function addBufferPrototypeMethods(proto) { | |||
| 1040 | 1040 | if (offset < 0 || offset > this.byteLength) { | |
| 1041 | 1041 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 1042 | 1042 | } | |
| 1043 | - if (length < 0 || length > this.byteLength - offset) { | ||
| 1043 | + if (length < 0) { | ||
| 1044 | 1044 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 1045 | 1045 | } | |
| 1046 | 1046 | return asciiWriteStatic(this, string, offset, length); | |
@@ -1051,7 +1051,7 @@ function addBufferPrototypeMethods(proto) { | |||
| 1051 | 1051 | if (offset < 0 || offset > this.byteLength) { | |
| 1052 | 1052 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 1053 | 1053 | } | |
| 1054 | - if (length < 0 || length > this.byteLength - offset) { | ||
| 1054 | + if (length < 0) { | ||
| 1055 | 1055 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 1056 | 1056 | } | |
| 1057 | 1057 | return latin1WriteStatic(this, string, offset, length); | |
@@ -1062,7 +1062,7 @@ function addBufferPrototypeMethods(proto) { | |||
| 1062 | 1062 | if (offset < 0 || offset > this.byteLength) { | |
| 1063 | 1063 | throw new ERR_BUFFER_OUT_OF_BOUNDS('offset'); | |
| 1064 | 1064 | } | |
| 1065 | - if (length < 0 || length > this.byteLength - offset) { | ||
| 1065 | + if (length < 0) { | ||
| 1066 | 1066 | throw new ERR_BUFFER_OUT_OF_BOUNDS('length'); | |
| 1067 | 1067 | } | |
| 1068 | 1068 | return utf8WriteStatic(this, string, offset, length); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,3 +106,18 @@ assert.strictEqual(Buffer.alloc(4) | |||
| 106 | 106 | assert.strictEqual(buf.write('ыы', 1, 'utf16le'), 4); | |
| 107 | 107 | assert.deepStrictEqual([...buf], [0, 0x4b, 0x04, 0x4b, 0x04, 0, 0, 0]); | |
| 108 | 108 | } | |
| 109 | + | ||
| 110 | + { | ||
| 111 | + const buf = Buffer.alloc(1); | ||
| 112 | + assert.strictEqual(buf.write('ww'), 1); | ||
| 113 | + assert.strictEqual(buf.toString(), 'w'); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + assert.throws(() => { | ||
| 117 | + const buf = Buffer.alloc(1); | ||
| 118 | + assert.strictEqual(buf.asciiWrite('ww', 0, -1)); | ||
| 119 | + assert.strictEqual(buf.latin1Write('ww', 0, -1)); | ||
| 120 | + assert.strictEqual(buf.utf8Write('ww', 0, -1)); | ||
| 121 | + }, common.expectsError({ | ||
| 122 | + code: 'ERR_BUFFER_OUT_OF_BOUNDS', | ||
| 123 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments