Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec() on a Buffer returns incorrect index #201

Closed
matthewvalentine opened this issue Dec 8, 2023 · 0 comments
Closed

exec() on a Buffer returns incorrect index #201

matthewvalentine opened this issue Dec 8, 2023 · 0 comments
Assignees
Labels
bug A reported bug. confirmed A confirmed bug.

Comments

@matthewvalentine
Copy link

matthewvalentine commented Dec 8, 2023

Calling exec() multiple times with a Buffer input produces increasingly incorrect values for .index. (Tested on 1.20.8 / commit 4e985f9)

This code:

const RE2 = require('./re2');
const r = new RE2('.', 'g');
const b = Buffer.from('test1test2');
while ((m = r.exec(b))) {
	console.log(m[0].toString(), m.index, r.lastIndex, String.fromCharCode(b[m.index]));
}

produces this output:

t 0 1 t
e 2 2 s
s 4 3 1
t 6 4 e
1 8 5 t
t 10 6
e 12 7
s 14 8
t 16 9
2 18 10

Compared to the same sort of thing with a string input:

t 0 1 t
e 1 2 e
s 2 3 s
t 3 4 t
1 4 5 1
t 5 6 t
e 6 7 e
s 7 8 s
t 8 9 t
2 9 10 2

The .index value in the Buffer input case doesn't seem to correspond to the value returned as the match, and also doesn't line up with the resulting .lastIndex. In fact, .index even starts exceeding the buffer length.

@uhop uhop self-assigned this Jan 18, 2024
@uhop uhop added the bug A reported bug. label Jan 18, 2024
@uhop uhop added the confirmed A confirmed bug. label Mar 3, 2024
@uhop uhop closed this as completed in f3f6d9f May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A reported bug. confirmed A confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants