From 3927eb059b1072402c1e2c9078ee5acbb990f583 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 1 Mar 2010 18:28:57 +0000 Subject: [PATCH] Fix not replacing escapes within a backreference match. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/gnu-regex@4718 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/document.c | 19 ++++--------------- src/search.c | 3 +-- src/utils.c | 5 ++++- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5ca0a42..935b8022 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Make regex search imply replacing escaped chars. * src/utils.c, src/utils.h, src/search.c, src/document.c: Fix regex search for '\\'. + * src/utils.c, src/search.c, src/document.c: + Fix not replacing escapes within a backreference match. 2010-02-26 Nick Treleaven diff --git a/src/document.c b/src/document.c index 15fb4269..e81a7517 100644 --- a/src/document.c +++ b/src/document.c @@ -2099,17 +2099,12 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text i++; continue; } - if (ptr[1] == '\\') - { - /* backslash escape, leave for later */ - i += 2; - continue; - } c = ptr[1]; - if (!isdigit(c)) + /* backslash or unnecessary escape */ + if (c == '\\' || !isdigit(c)) { - /* unnecessary escape */ - i += 2; + g_string_erase(str, i, 1); + i++; continue; } /* digit escape */ @@ -2121,12 +2116,6 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text i += strlen(grp); g_free(grp); } - /* now fix backslash, tabs, etc */ - if (!utils_str_replace_escape(str->str, FALSE)) - { - /* replace_text should already be checked as valid */ - g_assert_not_reached(); - } ret = sci_replace_target(sci, str->str, FALSE); g_string_free(str, TRUE); return ret; diff --git a/src/search.c b/src/search.c index c21e09b7..d5bcacba 100644 --- a/src/search.c +++ b/src/search.c @@ -1216,9 +1216,8 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) } if (search_flags_re & SCFIND_REGEXP) { - /* we don't want to interpret escapes for replace string yet, so check a copy */ if (! utils_str_replace_escape(find, TRUE) || - ! utils_str_replace_escape(utils_strdupa(replace), TRUE)) + ! utils_str_replace_escape(replace, TRUE)) goto fail; } else if (search_replace_escape_re) diff --git a/src/utils.c b/src/utils.c index c29ffd0e..147dd1b6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1045,7 +1045,8 @@ gchar **utils_read_file_in_array(const gchar *filename) /* Contributed by Stefan Oltmanns, thanks. - * Replaces \\, \r, \n, \t and \uXXX by their real counterparts */ + * Replaces \\, \r, \n, \t and \uXXX by their real counterparts. + * keep_backslash is used for regex strings to leave '\\' and '\?' in place */ gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash) { gsize i, j, len; @@ -1165,6 +1166,8 @@ gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash) } default: /* unnecessary escapes are allowed */ + if (keep_backslash) + string[j++] = '\\'; string[j] = string[i]; } }