Fix Bug 363427 - unsafe characters incorrectly parsed as part of URL
authorMontel Laurent <montel@kde.org>
Tue, 17 Jan 2017 06:41:53 +0000 (07:41 +0100)
committerMaximiliano Curia <maxy@debian.org>
Fri, 31 Mar 2017 13:53:53 +0000 (14:53 +0100)
Fix [Please visit our booth 24-25 http://example.com/]
CCBUG:363427

Gbp-Pq: Name Fix-Bug-363427-unsafe-characters-incorrectly-parsed-as-pa.patch

autotests/ktexttohtmltest.cpp
src/lib/text/ktexttohtml.cpp

index f48a31c172f5e0b613400b3f136e9ff24d715f3f..0c146232dedd5855f5cc5fba332b061681137819 100644 (file)
@@ -416,6 +416,14 @@ void KTextToHTMLTest::testHtmlConvert_data()
    QTest::newRow("url-with-ref-in-[") << "https://www.kde.org[1]"
                                << KTextToHTML::Options(KTextToHTML::PreserveSpaces)
                                << "<a href=\"https://www.kde.org\">https://www.kde.org</a>[1]";
+
+   QTest::newRow("url-with-ref-in-[2") << "[http://www.example.org/][whatever]"
+                               << KTextToHTML::Options(KTextToHTML::PreserveSpaces)
+                               << "[<a href=\"http://www.example.org/\">http://www.example.org/</a>][whatever]";
+
+   QTest::newRow("url-with-ref-in-]") << "[Please visit our booth 24-25 http://example.com/]"
+                               << KTextToHTML::Options(KTextToHTML::PreserveSpaces)
+                               << "[Please visit our booth 24-25 <a href=\"http://example.com/\">http://example.com/</a>]";
 }
 
 
index ecc1d228528b395a9c8993e020d61a253ee95e6f..d6c1f1c1ea7f342504a7c8394a2589626ddf9a60 100644 (file)
@@ -238,6 +238,8 @@ QString KTextToHTMLHelper::getUrl(bool *badurl)
                 previousCharIsSpace = true;
             } else if (!previousIsAnAnchor && mText[mPos] == QLatin1Char('[')) {
                 break;
+            } else if (!previousIsAnAnchor && mText[mPos] == QLatin1Char(']')) {
+                break;
             } else { // skip whitespace
                 if (previousCharIsSpace && mText[mPos] == QLatin1Char('<')) {
                     url.append(QLatin1Char(' '));