diff --git a/deps/streamsearch/sbmh.js b/deps/streamsearch/sbmh.js index 79d3150..ee04a12 100644 --- a/deps/streamsearch/sbmh.js +++ b/deps/streamsearch/sbmh.js @@ -114,7 +114,7 @@ SBMH.prototype._sbmh_feed = function (data) { // or until // the character to look at lies outside the haystack. while (pos < 0 && pos <= len - needleLength) { - ch = this._sbmh_lookup_char(data, pos + needleLastCharIndex) + ch = data[pos + needleLastCharIndex] if ( ch === needleLastChar && diff --git a/test/streamsearch.test.js b/test/streamsearch.test.js index f565496..75146f7 100644 --- a/test/streamsearch.test.js +++ b/test/streamsearch.test.js @@ -4,7 +4,7 @@ const { test } = require('node:test') const Streamsearch = require('../deps/streamsearch/sbmh') test('streamsearch', async t => { - t.plan(18) + t.plan(19) await t.test('should throw an error if the needle is not a String or Buffer', t => { t.plan(1) @@ -239,6 +239,34 @@ test('streamsearch', async t => { s.push(chunks[1]) }) + await t.test('should process two chunks with an overflowing needle /2', t => { + t.plan(9) + const expected = [ + [false, Buffer.from('t\0\0'), 0, 1], + [false, Buffer.from('eshello'), 0, 7] + ] + const needle = 'test' + const s = new Streamsearch(needle) + const chunks = [ + Buffer.from('t'), + Buffer.from('eshello') + ] + let i = 0 + s.on('info', (isMatched, data, start, end) => { + t.assert.deepStrictEqual(isMatched, expected[i][0]) + t.assert.deepStrictEqual(data, expected[i][1]) + t.assert.deepStrictEqual(start, expected[i][2]) + t.assert.deepStrictEqual(end, expected[i][3]) + i++ + if (i >= 2) { + t.assert.ok('pass') + } + }) + + s.push(chunks[0]) + s.push(chunks[1]) + }) + await t.test('should process two chunks with a potentially overflowing needle', t => { t.plan(13)