Fix Bug 343275 - [1] added at the end of a hyperlink
authorMontel Laurent <montel@kde.org>
Wed, 23 Nov 2016 07:07:25 +0000 (08:07 +0100)
committerMaximiliano Curia <maxy@debian.org>
Fri, 31 Mar 2017 13:53:53 +0000 (14:53 +0100)
FIXED-IN: 5.29
BUG: 343275

Gbp-Pq: Name Fix-Bug-343275-1-added-at-the-end-of-a-hyperlink.patch

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

index ccac29a0c70df0554a959707b3bf63ca3098168f..f48a31c172f5e0b613400b3f136e9ff24d715f3f 100644 (file)
@@ -411,6 +411,11 @@ void KTextToHTMLTest::testHtmlConvert_data()
    QTest::newRow("url-exec-html-6") << "https://<IP>:/\"><script>alert(1);</script><!--\nTest2"
                                << KTextToHTML::Options(KTextToHTML::PreserveSpaces)
                                << "https://&lt;IP&gt;:/&quot;&gt;&lt;script&gt;alert(1);&lt;/script&gt;&lt;!--\nTest2";
+
+
+   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]";
 }
 
 
index 30e0b5d04a8f4847a800a1cb3ba96756bc9cf421..ecc1d228528b395a9c8993e020d61a253ee95e6f 100644 (file)
@@ -229,12 +229,15 @@ QString KTextToHTMLHelper::getUrl(bool *badurl)
         int start = mPos;
         bool previousCharIsSpace = false;
         bool previousCharIsADoubleQuote = false;
+        bool previousIsAnAnchor = false;
         while ((mPos < mText.length()) &&
                 (mText[mPos].isPrint() || mText[mPos].isSpace()) &&
                 ((afterUrl.isNull() && !mText[mPos].isSpace()) ||
                  (!afterUrl.isNull() && mText[mPos] != afterUrl))) {
             if (mText[mPos].isSpace()) {
                 previousCharIsSpace = true;
+            } else if (!previousIsAnAnchor && mText[mPos] == QLatin1Char('[')) {
+                break;
             } else { // skip whitespace
                 if (previousCharIsSpace && mText[mPos] == QLatin1Char('<')) {
                     url.append(QLatin1Char(' '));
@@ -253,6 +256,9 @@ QString KTextToHTMLHelper::getUrl(bool *badurl)
                 } else {
                     previousCharIsADoubleQuote = false;
                 }
+                if (mText[mPos] == QLatin1Char('#')) {
+                    previousIsAnAnchor = true;
+                }
                 url.append(mText[mPos]);
                 if (url.length() > mMaxUrlLen) {
                     break;