diff options
author | Kai Uwe Broulik <kde@privat.broulik.de> | 2015-05-27 10:52:59 +0200 |
---|---|---|
committer | Kai Uwe Broulik <kde@privat.broulik.de> | 2015-07-03 14:47:14 +0000 |
commit | 8b205fd05dcdc4a0e7ec6b25429f691a0a9099fe (patch) | |
tree | f3f5f3526fa03e0f475535215ebb7502a44c3fb2 | |
parent | a3f686cf7cc14ff481b972b1170a7ff76d0e0fd0 (diff) |
Improve support for HTML entities in StyledText
This adds support for the non-breaking space character ( ) and properly
handling entities that do not end with a semicolon, such as a stray ampersand
in a text.
Change-Id: I2f157c9aa651b27511809d5a47ac07660949a290
Task-number: QTBUG-44869
Task-number: QTBUG-31816
Task-number: QTBUG-33368
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
-rw-r--r-- | src/quick/util/qquickstyledtext.cpp | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/quick/util/qquickstyledtext.cpp b/src/quick/util/qquickstyledtext.cpp index 5efe65ef44..6ed32c10e2 100644 --- a/src/quick/util/qquickstyledtext.cpp +++ b/src/quick/util/qquickstyledtext.cpp @@ -542,6 +542,12 @@ void QQuickStyledTextPrivate::parseEntity(const QChar *&ch, const QString &textI textOut += QChar(38); else if (entity == QLatin1String("quot")) textOut += QChar(34); + else if (entity == QLatin1String("nbsp")) + textOut += QChar(QChar::Nbsp); + return; + } else if (*ch == QLatin1Char(' ')) { + QStringRef entity(&textIn, entityStart - 1, entityLength + 1); + textOut += entity + *ch; return; } ++entityLength; diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp index b76218edb9..816440b191 100644 --- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp +++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp @@ -153,6 +153,8 @@ void tst_qquickstyledtext::textOutput_data() QTest::newRow("space trailing bold") << "this is <b>bold </b>" << "this is bold " << (FormatList() << Format(Format::Bold, 8, 5)) << false; QTest::newRow("img") << "a<img src=\"blah.png\"/>b" << "a b" << FormatList() << false; QTest::newRow("tag mix") << "<f6>ds<b></img><pro>gfh</b><w><w>ghj</stron><ql><sl><pl>dfg</j6><img><bol><r><prp>dfg<bkj></b><up><string>ewrq</al><bl>jklhj<zl>" << "dsgfhghjdfgdfgewrqjklhj" << (FormatList() << Format(Format::Bold, 2, 3)) << false; + QTest::newRow("named html entities") << "> < & " " << QLatin1String("> < & \" ") + QChar(QChar::Nbsp) << FormatList() << false; + QTest::newRow("invalid html entities") << "a &hello & a &goodbye;" << "a &hello & a " << FormatList() << false; } void tst_qquickstyledtext::textOutput() |