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 615895 - [PATCH] (indirectly) support non-NULL-terminated regexes in GRegex
[PATCH] (indirectly) support non-NULL-terminated regexes in GRegex
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gregex
2.24.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-04-15 22:30 UTC by Paolo Bonzini
Modified: 2011-08-23 20:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (5.51 KB, patch)
2010-04-15 22:35 UTC, Paolo Bonzini
none Details | Review
addendum (1.43 KB, patch)
2010-04-15 22:38 UTC, Paolo Bonzini
none Details | Review
updated patch (5.77 KB, patch)
2011-01-26 19:47 UTC, Paolo Bonzini
committed Details | Review
add g_regex_escape_nul (6.39 KB, patch)
2011-07-11 04:06 UTC, Matthias Clasen
committed Details | Review

Description Paolo Bonzini 2010-04-15 22:30:57 UTC
GRegex has no interface to match strings that are not NULL-terminated.

This patch adds an escaping function that can be used to this end, without redesigning the way the pattern is stored in GRegex objects and retrieved with g_regex_get_pattern.

As an alternative, this code could be used in a function that directly wraps g_regex_new.  That would be fine for me too, please review.

Testcases included.
Comment 1 Paolo Bonzini 2010-04-15 22:35:07 UTC
Created attachment 158849 [details] [review]
patch
Comment 2 Paolo Bonzini 2010-04-15 22:38:21 UTC
Created attachment 158857 [details] [review]
addendum
Comment 3 Behdad Esfahbod 2010-05-29 17:24:41 UTC
Note that your bug title is misleading, because it still doesn't support non-nul-terminated strings with your patch.

I like the patch though.
Comment 4 Paolo Bonzini 2011-01-20 17:25:46 UTC
ping?
Comment 5 Paolo Bonzini 2011-01-26 19:47:32 UTC
Created attachment 179398 [details] [review]
updated patch
Comment 6 Matthias Clasen 2011-02-15 04:46:41 UTC
Looks fine to me in principle. Looking at g_regex_escape_string for comparison, it lacks the backslash counting you have here - which looks like a bug...
Comment 7 Matthias Clasen 2011-02-15 04:47:33 UTC
Review of attachment 179398 [details] [review]:

Please commit
Comment 8 Matthias Clasen 2011-07-11 04:06:48 UTC
The following fix has been pushed:
5eee90f add g_regex_escape_nul
Comment 9 Matthias Clasen 2011-07-11 04:06:56 UTC
Created attachment 191673 [details] [review]
add g_regex_escape_nul

The function can be used to let regex compile non-NUL-terminated
strings without redesigning the way the pattern is stored in GRegex
objects and retrieved with g_regex_get_pattern.
Comment 10 Paolo Bonzini 2011-08-23 20:37:49 UTC
The backslash counting is only needed here because a string that is a backslash and a NUL must be escaped to "\\x00" (the backslash was uselessly escaping the NUL), while a string that is *two* backslashes and a NUL must be escaped to "\\\\\\x00" (the backslashes were their own escape, and a third must be added as part of escaping the NUL).  Confusing, yes...