After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 759744 - javascript regex bracketed group isn't closed if it ends in \\.
javascript regex bracketed group isn't closed if it ends in \\.
Status: RESOLVED OBSOLETE
Product: gtksourceview
Classification: Platform
Component: Syntax files
git master
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2015-12-21 14:55 UTC by Christoph Burschka
Modified: 2021-07-05 10:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to remove look-behind assertions and include "escape" context in "bracketed-regex" context. (1.17 KB, patch)
2015-12-22 00:20 UTC, Christoph Burschka
needs-work Details | Review
New patch including some example cases. (1.65 KB, patch)
2016-05-23 17:18 UTC, Christoph Burschka
needs-work Details | Review

Description Christoph Burschka 2015-12-21 14:55:32 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 ].
Comment 1 Christoph Burschka 2015-12-21 15:04:31 UTC
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.
Comment 2 Christoph Burschka 2015-12-22 00:18:37 UTC
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.
Comment 3 Christoph Burschka 2015-12-22 00:20:26 UTC
Created attachment 317764 [details] [review]
Patch to remove look-behind assertions and include "escape" context in "bracketed-regex" context.
Comment 4 Sébastien Wilmet 2016-01-03 14:51:59 UTC
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.
Comment 5 Tobias Schönberg 2016-02-06 09:06:21 UTC
@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!
Comment 6 Christoph Burschka 2016-05-23 17:18:13 UTC
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.
Comment 7 Sébastien Wilmet 2016-05-24 11:40:25 UTC
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.
Comment 8 GNOME Infrastructure Team 2021-07-05 10:59:40 UTC
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.