mna / pigeon

Command pigeon generates parsers in Go from a PEG grammar.
BSD 3-Clause "New" or "Revised" License
835 stars 66 forks source link

Fix Backslash Escapes Not Being Properly Handled #134

Closed mavolin closed 11 months ago

mavolin commented 11 months ago

It seems I accidentally introduced a bug in #117 which causes pigeon to think that a string/rune has not ended, if it contains \\"/\\'.

The reason behind this is simple: The CodeStringLiteral rule completely ignores backslashes unless they are followed by a quote. So, if a string contains the sequence \\", pigeon will ignore the first backslash and think that the remaining \" form an escape sequence and the string is not terminated.

The fix is, likewise, simple and just consumes \\ if it finds one, i.e. the current '"' (`\"` / [^"\r\n])* '"' becomes '"' (`\"` / `\\` / [^"\r\n])* '"'. That way the \\ in \\" is consumed first, and the string is then correctly recognized as terminated by the remaining ".

I have the fix ready and will open a PR directly after opening the issue.