Commit b0648685 authored by Kevin Funk's avatar Kevin Funk
Browse files

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.

BUG: 301362
REVIEW: 109554
parent e417ab76
......@@ -202,9 +202,7 @@ QString GrepOutputModel::replacementFor(const QString &text)
{
if(!m_finalUpToDate)
{
QString r = (m_regExp.patternSyntax() == QRegExp::Wildcard) ?
m_replacement : QString(m_replacement).replace("\\", "\\\\");
m_finalReplacement = substitudePattern(m_replacementTemplate, r);
m_finalReplacement = substitudePattern(m_replacementTemplate, m_replacement);
m_finalUpToDate = true;
}
return QString(text).replace(m_regExp, m_finalReplacement);
......
......@@ -111,6 +111,13 @@ void FindReplaceTest::testReplace_data()
<< (FileList() << File("myfile.txt", "some text\ndummy\nsome other test\n")
<< File("otherfile.txt", "some dummy text\n\n"));
// see bug: https://bugs.kde.org/show_bug.cgi?id=301362
QTest::newRow("LF character replace")
<< (FileList() << File("somefile.txt", "hello world\\n"))
<< "\\\\n" << "%s"
<< "\\n\\n" << "%s"
<< (FileList() << File("somefile.txt", "hello world\\n\\n"));
QTest::newRow("Template replace")
<< (FileList() << File("somefile.h", "struct Foo {\n void setFoo(int foo);\n};")
<< File("somefile.cpp", "instance->setFoo(0);\n setFoo(0); /*not replaced*/"))
......@@ -167,8 +174,9 @@ void FindReplaceTest::testReplace()
job->setRegexpFlag(true);
job->setCaseSensitive(true);
job->setProjectFilesFlag(false);
QVERIFY(job->exec());
QVERIFY(model->hasResults());
model->setReplacement(replace);
model->makeItemsCheckable(true);
model->doReplacements();
......
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