diff --git a/index.js b/index.js index ab9a997..c322c79 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ function BinarySplit (matcher) { } while (true) { - var idx = firstMatch(buf, offset) + var idx = firstMatch(buf, offset - matcher.length + 1) if (idx !== -1 && idx < buf.length) { this.push(buf.slice(lastMatch, idx)) offset = idx + matcher.length diff --git a/test.js b/test.js index 720e2c2..9998df1 100644 --- a/test.js +++ b/test.js @@ -90,3 +90,18 @@ test('chunked input with long matcher', function (t) { t.end() })) }) + +test('lookbehind in multi character matcher', function (t) { + var splitStream = splitTest('\r\n\r', function (err, items) { + if (err) throw err + t.equals(items.length, 2) + t.equals(items[0].toString(), 'a') + t.equals(items[1].toString(), 'b') + t.end() + }) + + splitStream.write('a\r') + splitStream.write('\n') + splitStream.write('\rb') + splitStream.end() +})