Kaydet (Commit) 3927eb05 authored tarafından Nick Treleaven's avatar Nick Treleaven

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
üst e669410a
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
Make regex search imply replacing escaped chars. Make regex search imply replacing escaped chars.
* src/utils.c, src/utils.h, src/search.c, src/document.c: * src/utils.c, src/utils.h, src/search.c, src/document.c:
Fix regex search for '\\'. 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 <nick(dot)treleaven(at)btinternet(dot)com> 2010-02-26 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
......
...@@ -2099,17 +2099,12 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text ...@@ -2099,17 +2099,12 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text
i++; i++;
continue; continue;
} }
if (ptr[1] == '\\')
{
/* backslash escape, leave for later */
i += 2;
continue;
}
c = ptr[1]; c = ptr[1];
if (!isdigit(c)) /* backslash or unnecessary escape */
if (c == '\\' || !isdigit(c))
{ {
/* unnecessary escape */ g_string_erase(str, i, 1);
i += 2; i++;
continue; continue;
} }
/* digit escape */ /* digit escape */
...@@ -2121,12 +2116,6 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text ...@@ -2121,12 +2116,6 @@ static gint geany_replace_target(ScintillaObject *sci, const gchar *replace_text
i += strlen(grp); i += strlen(grp);
g_free(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); ret = sci_replace_target(sci, str->str, FALSE);
g_string_free(str, TRUE); g_string_free(str, TRUE);
return ret; return ret;
......
...@@ -1216,9 +1216,8 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) ...@@ -1216,9 +1216,8 @@ on_replace_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
} }
if (search_flags_re & SCFIND_REGEXP) 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) || if (! utils_str_replace_escape(find, TRUE) ||
! utils_str_replace_escape(utils_strdupa(replace), TRUE)) ! utils_str_replace_escape(replace, TRUE))
goto fail; goto fail;
} }
else if (search_replace_escape_re) else if (search_replace_escape_re)
......
...@@ -1045,7 +1045,8 @@ gchar **utils_read_file_in_array(const gchar *filename) ...@@ -1045,7 +1045,8 @@ gchar **utils_read_file_in_array(const gchar *filename)
/* Contributed by Stefan Oltmanns, thanks. /* 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) gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
{ {
gsize i, j, len; gsize i, j, len;
...@@ -1165,6 +1166,8 @@ gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash) ...@@ -1165,6 +1166,8 @@ gboolean utils_str_replace_escape(gchar *string, gboolean keep_backslash)
} }
default: default:
/* unnecessary escapes are allowed */ /* unnecessary escapes are allowed */
if (keep_backslash)
string[j++] = '\\';
string[j] = string[i]; string[j] = string[i];
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment