Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f25c7ce
win,msi: Added Italian translation
mcollina Jan 12, 2016
9db861b
tools: increase lint coverage
Trott Jul 10, 2016
25b3ff4
test,doc: clarify `buf.indexOf(num)` input range
addaleax Jul 8, 2016
45a8fce
doc: fix typo in the CHANGELOG_V6
vsemozhetbyt Jul 6, 2016
8bbb3eb
tools: consistent .eslintrc formatting
silverwind Jul 12, 2016
e1e477e
win,msi: add zh-CN translations for the installer
pmq20 Jul 14, 2016
43b5bf4
inspector: Unify event queues
Jun 1, 2016
ccd4983
test: add common.rootDir
cjihrig Jul 12, 2016
f003465
fs: rename event to eventType in fs.watch listener
claudiorodriguez Jul 1, 2016
1af8c03
test: cleanup IIFE tests
cjihrig Jul 12, 2016
d224b47
test: improve error message in test-tick-processor
Trott Jul 12, 2016
f0d9610
doc: removed old git conflict markers from fs.md
jjhidalgar Jul 7, 2016
3b767b8
buffer: fix creating from zero-length ArrayBuffer
RReverser Jun 6, 2016
c10ade9
deps: back-port d721121 from v8 upstream
bnoordhuis Jul 9, 2016
a855b30
cluster: remove bind() and self
cjihrig Jul 13, 2016
46b9ef6
doc: fix typo in stream doc
Jul 14, 2016
c726ffb
doc: Warn against `uncaughtException` dependency.
lance Apr 25, 2016
9d9bd3c
timers: fix processing of nested timers
whitlockjc Jul 24, 2015
669af6e
doc: fix inconsistencies in code style
saadq Jul 15, 2016
17591c3
test: s/assert.fail/common.fail as appropriate
cjihrig Jul 14, 2016
3bd40ff
deps: no /safeseh for ml64.exe
indutny Jul 16, 2016
60c459c
util: inspect boxed symbols like other primitives
addaleax Jul 9, 2016
ba6ab7c
buffer: optimize hex_decode
chjj Jul 7, 2016
aa045cd
test: fix flaky test-http-server-consumed-timeout
Trott Jul 13, 2016
f7d3af6
doc: add `added:` information for stream
Jun 13, 2016
06bfb9e
src: fix handle leak in Buffer::New()
bnoordhuis Jul 13, 2016
978362d
src: fix handle leak in BuildStatsObject()
bnoordhuis Jul 13, 2016
e46efd9
src: fix handle leak in UDPWrap::Instantiate()
bnoordhuis Jul 13, 2016
61d88d9
src: remove unnecessary HandleScopes
bnoordhuis Jul 13, 2016
62a3ff2
doc: correct sample output of buf.compare
khalsah Jul 17, 2016
9d59b7d
test: avoid usage of mixed IPV6 addresses
gireeshpunathil Jul 13, 2016
059a721
doc: update CTC governance information
Trott Jul 13, 2016
f3182f6
deps: v8_inspector no longer depends on wtf
ofrobots Jul 15, 2016
bb187bb
deps: cherry-pick 1f53e42 from v8 upstream
bnoordhuis Jul 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test,doc: clarify buf.indexOf(num) input range
Hopefully clarify the behaviour of `buffer.indexOf()` and
`buffer.includes()` for numbers in that they will be
truncated to uint8s.

Add tests for that behaviour.

Fixes: #7591
PR-URL: #7611
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
addaleax authored and evanlucas committed Jul 15, 2016
commit 25b3ff402d50fe12d9088973d3f6fd0fa56ce6f6
6 changes: 4 additions & 2 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ Operates similar to [`Array#indexOf()`][] in that it returns either the
starting index position of `value` in Buffer or `-1` if the Buffer does not
contain `value`. The `value` can be a String, Buffer or Number. Strings are by
default interpreted as UTF8. Buffers will use the entire Buffer (to compare a
partial Buffer use [`buf.slice()`][]). Numbers can range from 0 to 255.
partial Buffer use [`buf.slice()`][]). Numbers will be interpreted as unsigned 8-bit
integer values between `0` and `255`.

```js
const buf = Buffer.from('this is a buffer');
Expand Down Expand Up @@ -1012,7 +1013,8 @@ added: v5.3.0
Operates similar to [`Array#includes()`][]. The `value` can be a String, Buffer
or Number. Strings are interpreted as UTF8 unless overridden with the
`encoding` argument. Buffers will use the entire Buffer (to compare a partial
Buffer use [`buf.slice()`][]). Numbers can range from 0 to 255.
Buffer use [`buf.slice()`][]). Numbers will be interpreted as unsigned 8-bit
integer values between `0` and `255`.

The `byteOffset` indicates the index in `buf` where searching begins.

Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-buffer-includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,19 @@ assert.throws(function() {
assert.throws(function() {
b.includes([]);
});

// test truncation of Number arguments to uint8
{
const buf = Buffer.from('this is a test');
assert.ok(buf.includes(0x6973));
assert.ok(buf.includes(0x697320));
assert.ok(buf.includes(0x69732069));
assert.ok(buf.includes(0x697374657374));
assert.ok(buf.includes(0x69737374));
assert.ok(buf.includes(0x69737465));
assert.ok(buf.includes(0x69737465));
assert.ok(buf.includes(-140));
assert.ok(buf.includes(-152));
assert.ok(!buf.includes(0xff));
assert.ok(!buf.includes(0xffff));
}
16 changes: 16 additions & 0 deletions test/parallel/test-buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,19 @@ pattern = reallyLong.slice(0, 1000000); // First 1/5th.
assert.equal(3932160, reallyLong.lastIndexOf(pattern));
pattern = reallyLong.slice(0, 2000000); // first 2/5ths.
assert.equal(0, reallyLong.lastIndexOf(pattern));

// test truncation of Number arguments to uint8
{
const buf = Buffer.from('this is a test');
assert.strictEqual(buf.indexOf(0x6973), 3);
assert.strictEqual(buf.indexOf(0x697320), 4);
assert.strictEqual(buf.indexOf(0x69732069), 2);
assert.strictEqual(buf.indexOf(0x697374657374), 0);
assert.strictEqual(buf.indexOf(0x69737374), 0);
assert.strictEqual(buf.indexOf(0x69737465), 11);
assert.strictEqual(buf.indexOf(0x69737465), 11);
assert.strictEqual(buf.indexOf(-140), 0);
assert.strictEqual(buf.indexOf(-152), 1);
assert.strictEqual(buf.indexOf(0xff), -1);
assert.strictEqual(buf.indexOf(0xffff), -1);
}