buffer: fix indexOf for empty searches
Make searches for empty subsequences return 0
for buffer.indexOf()
and buffer.length
for buffer.lastIndexOf()
, because those
are the indices of the first and last occurrence of an empty
subsequence, respectively.
Make searches for empty subsequences do exactly what String.prototype.indexOf()
does.
Fixes: https://github.com/nodejs/node/issues/13023
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
buffer
/cc @nodejs/buffer and because people might to consider this a semver-major change (I would not) @nodejs/ctc