Skip to content

Commit

Permalink
fix: don't call false if no new info was processed
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Aug 14, 2024
1 parent 904c12f commit 5ee225e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const Match = class {
this.#lookbehind.set(buffer.subarray(index));
this.#lookbehindSize = buffer.length - index;

if (index) {
if (index !== this.#bufferIndex) {
this.#callback(false, this.#bufferIndex, index, null, buffer);
}
} else {
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,24 @@ test("pattern test", (t, done) => {
match.write("sHello, ");
match.write("World!");
});

test("pattern test /2", (t, done) => {
let buffer = Buffer.from([]);

const m = new Match("Hello, World!", (isMatch, start, end, l, b) => {
if (!isMatch) {
buffer = Buffer.concat([buffer, (l ?? b).subarray(start, end)]);
}
});

m.write('"Hello, ');
m.write('World!"');
m.write("...");
m.write("...");
m.write("...");
m.write("Hello, World!");
m.write("Hello, Gurgun!");

assert.deepEqual(buffer.toString("utf8"), `"".........Hello, Gurgun`);
done();
});

0 comments on commit 5ee225e

Please sign in to comment.