robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
8.01k stars 584 forks source link

fix: missing flag from regex literal in corner case #529

Closed psve closed 1 month ago

psve commented 2 months ago

In the specific corner case where a regex contains a flag but is not followed by any symbols, the ast.RegExpLiteral.Literal value would drop (part of) that flag.

This happens because the p.next() call during the parsing of the flag wouldn't actually advance the p.chrOffset, and thus endOffset would be erroneously adjusted.

The fix is just to use the current p.chrOffset and then call p.next() afterwards.

psve commented 1 month ago

@stevenh , I removed the erroneous import, the linter checks should pass now.

stevenh commented 1 month ago

Thanks for the PR @psve 🥇