diff options
author | Anna Henningsen <anna@addaleax.net> | 2016-05-02 07:51:33 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2016-05-04 22:14:15 +0200 |
commit | 4d49bcb73edb12992a0a01c10c9d961a59b6fee4 (patch) | |
tree | 76de519fe2b295d069a6e902d77133e1a0c106ca /test/parallel/test-buffer-indexof.js | |
parent | 5defa0cbaa9c6d72420df32f6a67fe55edc8160a (diff) | |
download | android-node-v8-4d49bcb73edb12992a0a01c10c9d961a59b6fee4.tar.gz android-node-v8-4d49bcb73edb12992a0a01c10c9d961a59b6fee4.tar.bz2 android-node-v8-4d49bcb73edb12992a0a01c10c9d961a59b6fee4.zip |
buffer: fix UCS2 indexOf for odd buffer length
Fix `buffer.indexOf` for the case that the haystack has odd length
and the needle is not found in it. `StringSearch()` would return
the length of the buffer in multiples of `sizeof(uint16_t)`, but
checking that against `haystack_length` would not work if the latter
one was odd.
PR-URL: https://github.com/nodejs/node/pull/6511
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-indexof.js')
-rw-r--r-- | test/parallel/test-buffer-indexof.js | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-indexof.js b/test/parallel/test-buffer-indexof.js index 0aeb066f21..0cdce9cf25 100644 --- a/test/parallel/test-buffer-indexof.js +++ b/test/parallel/test-buffer-indexof.js @@ -228,6 +228,9 @@ assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1); assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'utf8'), 0); assert.strictEqual(Buffer.from('aaaa').indexOf('你好', 'ucs2'), -1); +// Haystack has odd length, but the needle is UCS2. +assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1); + { // Find substrings in Utf8. const lengths = [1, 3, 15]; // Single char, simple and complex. |