From 1fb24d6852e34bd58f35172dea4bfd4c41236689 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 21 Jun 2010 12:07:20 +0200 Subject: Make sure that
is seen as a valid tag in Qt::mightBeRichText() The W3C online markup validation test verifies that
is indeed valid XHTML and
is also valid so this ensures that this case is accounted for. The existing test was expanded to accout for each of these cases. Task-number: QTBUG-1786 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextdocument.cpp | 2 ++ tests/auto/qtextdocument/tst_qtextdocument.cpp | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index c7a9756..65e88ab 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -127,6 +127,8 @@ bool Qt::mightBeRichText(const QString& text) tag += text[i]; else if (!tag.isEmpty() && text[i].isSpace()) break; + else if (!tag.isEmpty() && text[i] == QLatin1Char('/') && i + 1 == close) + break; else if (!text[i].isSpace() && (!tag.isEmpty() || text[i] != QLatin1Char('!'))) return false; // that's not a tag } diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 51aee74..808299b 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -98,6 +98,7 @@ private slots: void noundo_isModified2(); void noundo_isModified3(); void mightBeRichText(); + void mightBeRichText_data(); void task240325(); @@ -679,13 +680,32 @@ void tst_QTextDocument::noundo_isModified3() QVERIFY(doc->isModified()); } -void tst_QTextDocument::mightBeRichText() +void tst_QTextDocument::mightBeRichText_data() { const char qtDocuHeader[] = "\n" "\n" ""; QVERIFY(Qt::mightBeRichText(QString::fromLatin1(qtDocuHeader))); + QTest::addColumn("input"); + QTest::addColumn("result"); + + QTest::newRow("documentation-header") << QString("\n" + "\n" + "") + << true; + QTest::newRow("br-nospace") << QString("Test
new line") << true; + QTest::newRow("br-space") << QString("Test
new line") << true; + QTest::newRow("br-invalidspace") << QString("Test
new line") << false; + QTest::newRow("invalid closing tag") << QString("Test