diff --git a/autotests/src/variable_test.cpp b/autotests/src/variable_test.cpp --- a/autotests/src/variable_test.cpp +++ b/autotests/src/variable_test.cpp @@ -174,6 +174,16 @@ QString out; + // Test invalid ones: + editor->expandText(QStringLiteral("%{}"), view, out); + QCOMPARE(out, QStringLiteral("%{}")); + editor->expandText(QStringLiteral("%{"), view, out); + QCOMPARE(out, QStringLiteral("%{")); + editor->expandText(QStringLiteral("%{{}"), view, out); + QCOMPARE(out, QStringLiteral("%{{}")); + editor->expandText(QStringLiteral("%{{}}"), view, out); + QCOMPARE(out, QStringLiteral("%{{}}")); + // Document:FileBaseName editor->expandText(QStringLiteral("%{Document:FileBaseName}"), view, out); QCOMPARE(out, QStringLiteral("kate-v5")); diff --git a/src/utils/katevariableexpansionhelpers.cpp b/src/utils/katevariableexpansionhelpers.cpp --- a/src/utils/katevariableexpansionhelpers.cpp +++ b/src/utils/katevariableexpansionhelpers.cpp @@ -51,7 +51,6 @@ int nesting = 0; while (pos < len) { - ++pos; const QChar c = str[pos]; if (c == QLatin1Char('}')) { if (nesting == 0) { @@ -61,6 +60,7 @@ } else if (c == QLatin1Char('{')) { nesting++; } + ++pos; } return -1; }