Skip to content

Commit

Permalink
Fixed a typo in the buffer's path.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhop committed May 7, 2024
1 parent f3f6d9f commit 20a2523
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ NAN_METHOD(WrappedRE2::Match)
if (!re2->global && re2->hasIndices)
{
auto pair = Nan::New<v8::Array>();
auto offset = getUtf16Length(a.data + lastIndex, data);
auto length = getUtf16Length(data, data + item.size());
auto offset = data - a.data - lastIndex;
auto length = item.size();
Nan::Set(pair, 0, Nan::New<v8::Integer>(static_cast<int>(offset)));
Nan::Set(pair, 1, Nan::New<v8::Integer>(static_cast<int>(offset + length)));
Nan::Set(indices, i, pair);
Expand Down
17 changes: 17 additions & 0 deletions tests/test_match.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,22 @@ unit.add(module, [
eval(t.TEST("t.unify(result, ['a', 'a'])"));
eval(t.TEST("!('indices' in result)"));
eval(t.TEST("!('groups' in result)"));
},

function test_matchLastIndex(t) {
'use strict';

const re = new RE2(/./g), pattern = 'Я123';

re.lastIndex = 2;
const result1 = pattern.match(re);
eval(t.TEST("t.unify(result1, ['Я', '1', '2', '3'])"));
eval(t.TEST("re.lastIndex === 0"));

const re2 = RE2(re);
re2.lastIndex = 2;
const result2 = re2.match(Buffer.from(pattern));
eval(t.TEST("t.unify(result2.map(b => b.toString()), ['Я', '1', '2', '3'])"));
eval(t.TEST("re2.lastIndex === 0"));
}
]);

0 comments on commit 20a2523

Please sign in to comment.