| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 26e695c commit ea72e9f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -890,7 +890,8 @@ Operates similar to [`Array#indexOf()`][] in that it returns either the | |||
| 890 | 890 | starting index position of `value` in Buffer or `-1` if the Buffer does not | |
| 891 | 891 | contain `value`. The `value` can be a String, Buffer or Number. Strings are by | |
| 892 | 892 | default interpreted as UTF8. Buffers will use the entire Buffer (to compare a | |
| 893 | - partial Buffer use [`buf.slice()`][]). Numbers can range from 0 to 255. | ||
| 893 | + partial Buffer use [`buf.slice()`][]). Numbers will be interpreted as unsigned 8-bit | ||
| 894 | + integer values between `0` and `255`. | ||
| 894 | 895 | ||
| 895 | 896 | ```js | |
| 896 | 897 | const buf = new Buffer('this is a buffer'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -302,3 +302,19 @@ assert.throws(function() { | |||
| 302 | 302 | assert.throws(function() { | |
| 303 | 303 | b.indexOf([]); | |
| 304 | 304 | }); | |
| 305 | + | ||
| 306 | + // test truncation of Number arguments to uint8 | ||
| 307 | + { | ||
| 308 | + const buf = Buffer.from('this is a test'); | ||
| 309 | + assert.strictEqual(buf.indexOf(0x6973), 3); | ||
| 310 | + assert.strictEqual(buf.indexOf(0x697320), 4); | ||
| 311 | + assert.strictEqual(buf.indexOf(0x69732069), 2); | ||
| 312 | + assert.strictEqual(buf.indexOf(0x697374657374), 0); | ||
| 313 | + assert.strictEqual(buf.indexOf(0x69737374), 0); | ||
| 314 | + assert.strictEqual(buf.indexOf(0x69737465), 11); | ||
| 315 | + assert.strictEqual(buf.indexOf(0x69737465), 11); | ||
| 316 | + assert.strictEqual(buf.indexOf(-140), 0); | ||
| 317 | + assert.strictEqual(buf.indexOf(-152), 1); | ||
| 318 | + assert.strictEqual(buf.indexOf(0xff), -1); | ||
| 319 | + assert.strictEqual(buf.indexOf(0xffff), -1); | ||
| 320 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments