Bug 301362

Summary: Find/replace in Files escapes the "\" (0x5C) character when trying to insert it via the replace action
Product: kdevelop Reporter: Claus Christmann <hcc>
Component: QEditorAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: git master   
Target Milestone: 4.3.0   
Platform: openSUSE RPMs   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: The HelloWorld example mentioned/used in the bug report.

Description Claus Christmann 2012-06-07 14:24:48 UTC
When I use the "Find/replace in Files" tool, I don't seem to be able to insert text which contains the "\" (0x5C) character as some internal logic automatically escapes it with a another "\" (0x5C), rendering the resulting code useless.

Goal:    "\n" -> "\n\n"
Actual Result: "\n" -> "\\n\\n"


Reproducible: Always

Steps to Reproduce:
Use this simple project:

#include <cstdio>
int main(int argc, char **argv) {
    std::printf("Hello World.\n");
    return 0;
}

1.Open the Find/replace in Files tool, search for the character sequence "\n"" to catch the LF in the printf. Put \n" as the Pattern, leave Template and Replacement Template both as %s, i.e. verbatim
2. Hit Search
3. Put \n\n" in the Replacement Text box
4. Mouse over the found locations to preview the replacement action, notice the double \\
Actual Results:  
#include <cstdio>
int main(int argc, char **argv) {
    std::printf("Hello World.\\n\\n");
    return 0;
}

Expected Results:  
#include <cstdio>
int main(int argc, char **argv) {
    std::printf("Hello World.\n\n");
    return 0;
}

Could be very much the case that I am simply not able to do this as a regex, but I think this should be doable as a simple character replacement as there are only printable characters (as opposed to an actual LF) involved.
Comment 1 Claus Christmann 2012-06-07 14:28:29 UTC
Created attachment 71642 [details]
The HelloWorld example mentioned/used in the bug report.
Comment 2 Kevin Funk 2013-03-19 20:54:10 UTC
Git commit b06486852b36688ab91d306d32e7975c8cca9ca4 by Kevin Funk.
Committed on 19/03/2013 at 21:48.
Pushed by kfunk into branch '1.5'.

Fix issue in grepview plugin

It was impossible to replace "\n" with "\n\n" before.

I really don't know what the code path replacing '\\' by '\\\\'
was supposed to do. It replaced characters in the replacement string in
case the input regexp was marked with QRegExp::Wildcard. But I have no
clue why the replacement string should depend on that.

Add tests.
REVIEW: 109554

M  +1    -3    plugins/grepview/grepoutputmodel.cpp
M  +9    -1    plugins/grepview/tests/findreplacetest.cpp

http://commits.kde.org/kdevplatform/b06486852b36688ab91d306d32e7975c8cca9ca4