GNOME Bugzilla – Bug 759744
javascript regex bracketed group isn't closed if it ends in \\.
Last modified: 2021-07-05 10:59:40 UTC
/[\\]/ is a valid regex literal that matches a backslash. Unfortunately, the escaped backslash seems to be incorrectly recognized as a single backslash followed by an escaped ], so the bracketed group isn't terminated and the regex literal swallows everything after it until it encounters another ].
The same applies to the start - /\\[ab]/ matches a backslash followed by a or b, but the syntax highlighter doesn't recognize the start of the bracketed expression. The problem seems to be the negative look-behind (?<!\\). In fact, the bracket characters must be allowed to be preceded by an even number of backslashes - which is admittedly not feasible with a look-behind due to the fixed length requirement.
I might be misunderstanding something, but it seems that a look-behind assertion shouldn't be used here anyway: The "regex-simple" context already defines an "escape" context that prevents an escaped [ from opening the bracketed-regex, so the (?<!\\) in <start> is redundant. To ensure that a bracketed-regex isn't closed prematurely by an escaped ], all that is needed is to include the "escape" context in the "bracketed-regex" context as well. I'll add a patch.
Created attachment 317764 [details] [review] Patch to remove look-behind assertions and include "escape" context in "bracketed-regex" context.
Review of attachment 317764 [details] [review]: Makes sense. Can you add code examples in tests/syntax-highlighting/file.js ? For the commit message, a better title is: > javascript.lang: allow \\ in bracketed groups With the bug URL at the end of the commit message.
@Christoph: Just a reminder that your patch needs some minor fixes. It would be great if we could merge it soon, as it is a major bug in the highlighting. Thanks!
Created attachment 328399 [details] [review] New patch including some example cases. Sorry I've had a hectic couple of months. :) Here's the new patch.
Review of attachment 328399 [details] [review]: There are still bugs. The second and 4th examples are not highlighted as a regex because the preceding line ends with \. The bug is maybe unrelated to this one, but there is something going wrong. When the \ on the preceding lines are removed, the regexes are still not highlighted correctly. I think it would be much simpler to not highlight bracketed expressions in a regex. Just highlight escaped sequences. So the context 'regex-bracketed' can be removed altogether.
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/gtksourceview/-/issues/ Thank you for your understanding and your help.