From bb875a5c56d519a05ebc3d958c2fb9dfdfc5ad57 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 14 May 2017 19:57:52 +0200 Subject: [PATCH 1/2] buffer: fix indexOf for empty searches Make searches for empty subsequences do exactly what `String.prototype.indexOf()` does. Fixes: https://github.com/nodejs/node/issues/13023 --- doc/api/buffer.md | 6 ++++ lib/buffer.js | 2 +- src/node_buffer.cc | 46 +++++++++++++++++++-------- test/parallel/test-buffer-includes.js | 16 +++++----- test/parallel/test-buffer-indexof.js | 24 +++++++------- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/doc/api/buffer.md b/doc/api/buffer.md index 3a6a048417239a..9b3f3f8b4b751b 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -1340,6 +1340,10 @@ console.log(b.indexOf('b', null)); console.log(b.indexOf('b', [])); ``` +If `value` is an empty string or empty `Buffer` and `byteOffset` is less +than `buf.length`, `byteOffset` will be returned. If `value` is empty and +`byteOffset` is at least `buf.length`, `buf.length` will be returned. + ### buf.keys()