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 515944 - Double replace
Double replace
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gregex
2.15.x
Other All
: Normal normal
: ---
Assigned To: Marco Barisione
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-02-12 06:25 UTC by Maciej (Matthew) Piechotka
Modified: 2008-02-17 14:09 UTC
See Also:
GNOME target: ---
GNOME version: 2.21/2.22



Description Maciej (Matthew) Piechotka 2008-02-12 06:25:16 UTC
Please describe the problem:
String was double replaced

Steps to reproduce:
#include <glib.h>

int main() {
	GRegex *regex = g_regex_new ("(?=[A-Z0-9])", 0, 0, NULL);
	g_printf("%s", g_regex_replace_literal (regex, "RegExTest", -1, 1, "_", 0, NULL));
}


Actual results:
Reg__Ex__Test

Expected results:
Reg_Ex_Test

Does this happen every time?
Yes

Other information:
Comment 1 Marco Barisione 2008-02-12 11:08:04 UTC
The expected result should be '_Reg_Ex_Test', in Python you get:
>>> import re
>>> re.sub('(?=[A-Z0-9])', '_', 'RegExTest')
'_Reg_Ex_Test'

I'm going to try to fix the bug in the next days, for now you can use a workaround (to get 'Reg_Ex_Test', not '_Reg_Ex_Test':

#include <glib.h>

int main() {
        GRegex *regex = g_regex_new ("(.)(?=[A-Z0-9])", 0, 0, NULL);
        g_printf("%s", g_regex_replace (regex, "RegExTest", -1, 1, "\\1_",
0, NULL));
}
Comment 2 Maciej (Matthew) Piechotka 2008-02-12 11:29:13 UTC
(In reply to comment #1)
> The expected result should be '_Reg_Ex_Test', in Python you get:
> >>> import re
> >>> re.sub('(?=[A-Z0-9])', '_', 'RegExTest')
> '_Reg_Ex_Test'
> 
> I'm going to try to fix the bug in the next days, for now you can use a
> workaround (to get 'Reg_Ex_Test', not '_Reg_Ex_Test':
> 

You misunderstend me:
1. Starting position is *1* (not *0*) so there is no leading '_'. Both in expected as in actual result.
2. It inserts double '_'
3. Your code results in 'Re_E_Test'
Comment 3 Marco Barisione 2008-02-12 11:39:02 UTC
Sorry, didn't see the 1.
Here my code works with glib 2.14.6 and PCRE 7.6, I will try with glib 2.15 later.
Comment 4 Maciej (Matthew) Piechotka 2008-02-12 11:40:40 UTC
In perl all is ok. My glib version is 2.15.4
Comment 5 Marco Barisione 2008-02-17 14:09:03 UTC
2008-02-17  Marco Barisione  <marco@barisione.org>

	* glib/gregex.c: (match_info_new), (g_match_info_next): Don't return
	duplicate matches when matching empty strings.  (#515944)
	* tests/regex-test.c: Add tests.