| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 653f092 commit 0276e9e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -789,11 +789,10 @@ Buffer.prototype.toJSON = function() { | |||
| 789 | 789 | ||
| 790 | 790 | ||
| 791 | 791 | function adjustOffset(offset, length) { | |
| 792 | - offset = +offset; | ||
| 793 | - if (offset === 0 || Number.isNaN(offset)) { | ||
| 792 | + offset |= 0; | ||
| 793 | + if (offset === 0) { | ||
| 794 | 794 | return 0; | |
| 795 | - } | ||
| 796 | - if (offset < 0) { | ||
| 795 | + } else if (offset < 0) { | ||
| 797 | 796 | offset += length; | |
| 798 | 797 | return offset > 0 ? offset : 0; | |
| 799 | 798 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,3 +62,13 @@ assert.strictEqual(Buffer.alloc(0).slice(0, 1).length, 0); | |||
| 62 | 62 | ||
| 63 | 63 | // slice(0,0).length === 0 | |
| 64 | 64 | assert.strictEqual(0, Buffer.from('hello').slice(0, 0).length); | |
| 65 | + | ||
| 66 | + { | ||
| 67 | + // Regression tests for https://github.com/nodejs/node/issues/9096 | ||
| 68 | + const buf = Buffer.from('abcd'); | ||
| 69 | + assert.strictEqual(buf.slice(buf.length / 3).toString(), 'bcd'); | ||
| 70 | + assert.strictEqual( | ||
| 71 | + buf.slice(buf.length / 3, buf.length).toString(), | ||
| 72 | + 'bcd' | ||
| 73 | + ); | ||
| 74 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments