Merge lp:~macslow/unity-notifications/fix-1335787 into lp:unity-notifications

Proposed by Mirco Müller
Status: Merged
Approved by: Michał Sawicz
Approved revision: 220
Merged at revision: 217
Proposed branch: lp:~macslow/unity-notifications/fix-1335787
Merge into: lp:unity-notifications
Diff against target: 125 lines (+64/-5)
3 files modified
include/Notification.h (+3/-0)
src/Notification.cpp (+14/-5)
test/notificationtest.cpp (+47/-0)
To merge this branch: bzr merge lp:~macslow/unity-notifications/fix-1335787
Reviewer Review Type Date Requested Status
Michał Sawicz Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+227334@code.launchpad.net

Commit message

Added an internal text-filter to setSummary() and setBody()

It strips or converts HTML and other markup-text, thus no special formatting happens during rendering via QML in the Notification-renderer.

Description of the change

Added an internal text-filter to setSummary() and setBody() (with a corresponding unit-test) which strips or converts HTML and other markup-text, thus no special formatting happens during rendering via QML in the Notification-renderer.

* Are there any related MPs required for this MP to build/function as expected? Please list.
Yes. It works optimal in tandem with lp:~macslow/unity8/fix-1335787

* Did you perform an exploratory manual test run of your code change and any related functionality?
Yes.

* Did you make sure that your branch does not contain spurious tags?
Yes.

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
Not applicable.

* If you changed the UI, has there been a design review?
Not applicable.

To post a comment you must log in.
216. By Mirco Müller

Merged with trunk and resolved conflicts.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

I'm really not sure this kind of filtering belongs here :|

Why don't we just require the consumers to send us unescaped strings? UI-side we can ignore tags by using http://qt-project.org/doc/qt-5/qml-qtquick-text.html#textFormat-prop, forcing it to PlainText, which will ignore tags and such.

review: Needs Information
Revision history for this message
Mirco Müller (macslow) wrote :

Using...

textFormat: Text.PlainText

... for the summary- and body-text (in the renderer/unity8) does prevent any inlined formatting tags from being applied or URLs to be highlighted, it does not strip any of the tags-text. The only issue I see with using the Text.PlainText approach, is that no single app (neither core nor 3rd-party) knows about this and probably sends "tag-polluted" text to the notifications. Thus it will make notifications look bad and easily exceed the new two-line limit Design wants to see enforced for body-text.

Regarding special HTML-characters like...

< < < > > > & & ' &

... I'm not sure how and where to make use of the C++-class QTextDocument. I would like to leave that within the responsibility of the sending app too, since we already demand tag-free text with the Text.PlainText approach.

Revision history for this message
Mirco Müller (macslow) wrote :

Of the initial 33 text-filter tests these 7 fail when using QTextDocument...

"<img src=\"foobar.png\" />Nothing to see" -> "Nothing to see"
"><", -> "><"
"<>", -> "<>"
"< this is not a tag >" -> "< this is not a tag >"
"14 < 42" -> "14 < 42"
"First line <br dumb> \r \n Second line" -> "First line\nSecond line"
"First line\n<br /> <br>\n2nd line\r\n3rd line" -> "First line\n2nd line\n3rd line"

217. By Mirco Müller

Updated the text-filter to only use QTextDocument, thus had to skip 7 of the initial 33 test-cases.

218. By Mirco Müller

Use the data-driven approach for the text-filter test.

219. By Mirco Müller

Oops.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

See inline

220. By Mirco Müller

Use tag-names for text-filter unit-tests.

Revision history for this message
Michał Sawicz (saviq) wrote :

Yup.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/Notification.h'
2--- include/Notification.h 2014-07-14 13:54:41 +0000
3+++ include/Notification.h 2014-09-10 15:07:11 +0000
4@@ -118,6 +118,9 @@
5 Q_INVOKABLE void close();
6
7 bool operator<(const Notification &n) const; // Order by "interestingness".
8+
9+private:
10+ QString filterText(const QString& text);
11 };
12
13 #endif /* NOTIFICATION_HPP_ */
14
15=== modified file 'src/Notification.cpp'
16--- src/Notification.cpp 2014-07-21 16:59:41 +0000
17+++ src/Notification.cpp 2014-09-10 15:07:11 +0000
18@@ -21,6 +21,7 @@
19 #include "NotificationServer.h"
20 #include "Notification.h"
21 #include <string>
22+#include <QTextDocument>
23
24 using namespace std;
25
26@@ -81,9 +82,10 @@
27 }
28
29 void Notification::setBody(const QString &text) {
30- if(p->body != text) {
31- p->body = text;
32- Q_EMIT bodyChanged(text);
33+ QString filtered = filterText(text);
34+ if(p->body != filtered) {
35+ p->body = filtered;
36+ Q_EMIT bodyChanged(p->body);
37 Q_EMIT dataChanged(p->id);
38 }
39 }
40@@ -153,8 +155,9 @@
41 }
42
43 void Notification::setSummary(const QString &summary) {
44- if(p->summary != summary) {
45- p->summary = summary;
46+ QString filtered = filterText(summary);
47+ if(p->summary != filtered) {
48+ p->summary = filtered;
49 Q_EMIT summaryChanged(p->summary);
50 Q_EMIT dataChanged(p->id);
51 }
52@@ -248,3 +251,9 @@
53 void Notification::close() {
54 Q_EMIT completed(p->id);
55 }
56+
57+QString Notification::filterText(const QString& text) {
58+ QTextDocument filtered;
59+ filtered.setHtml(text);
60+ return filtered.toPlainText();
61+}
62
63=== modified file 'test/notificationtest.cpp'
64--- test/notificationtest.cpp 2014-02-18 14:51:44 +0000
65+++ test/notificationtest.cpp 2014-09-10 15:07:11 +0000
66@@ -16,6 +16,8 @@
67 void testVisualSDQueueWithoutCritical();
68 void testVisualSDQueueWithCritical();
69 void testVisualSDQueueMax();
70+ void testTextFilter();
71+ void testTextFilter_data();
72 };
73
74 void TestNotifications::testSimpleInsertion() {
75@@ -179,5 +181,50 @@
76 QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-4"));
77 }
78
79+void TestNotifications::testTextFilter_data() {
80+ QTest::addColumn<QString>("string");
81+ QTest::addColumn<QString>("result");
82+
83+ QTest::newRow("URL") << "<a href=\"http://www.ubuntu.com/\">Ubuntu</a>" << "Ubuntu";
84+ QTest::newRow("as is") << "Don't rock the boat" << "Don't rock the boat";
85+ QTest::newRow("italic") << "<i>Not italic</i>" << "Not italic";
86+ QTest::newRow("unterline") << "<u>Test</u>" << "Test";
87+ QTest::newRow("bold") << "<b>Bold</b>" << "Bold";
88+ QTest::newRow("span") << "<span>Span</span>" << "Span";
89+ QTest::newRow("s-tag") << "<s>E-flat</s>" << "E-flat";
90+ QTest::newRow("sub") << "<sub>Sandwich</sub>" << "Sandwich";
91+ QTest::newRow("small") << "<small>Fry</small>" << "Fry";
92+ QTest::newRow("tt") << "<tt>Testing tag</tt>" << "Testing tag";
93+ QTest::newRow("html") << "<html>Surrounded by html</html>" << "Surrounded by html";
94+ QTest::newRow("qt") << "<qt>Surrounded by qt</qt>" << "Surrounded by qt";
95+ QTest::newRow("quotes") << "\"Film spectators are quiet vampires.\"" << "\"Film spectators are quiet vampires.\"";
96+ QTest::newRow("> 1/4") << "7 > 3" << "7 > 3";
97+ QTest::newRow("> 2/4") << "7 &gt; 3" << "7 > 3";
98+ QTest::newRow("> 3/4") << "7 &#62; 3" << "7 > 3";
99+ QTest::newRow("> 4/4") << "7 &#x3e; 3" << "7 > 3";
100+ QTest::newRow("< 1/3") << "14 &lt; 42" << "14 < 42";
101+ QTest::newRow("< 2/3") << "14 &#60; 42" << "14 < 42";
102+ QTest::newRow("< 3/3") << "14 &#x3c; 42" << "14 < 42";
103+ QTest::newRow("& 1/4") << "War & Peace" << "War & Peace";
104+ QTest::newRow("& 2/4") << "Law &#38; Order" << "Law & Order";
105+ QTest::newRow("& 3/4") << "Love &#x26; War" << "Love & War";
106+ QTest::newRow("& 4/4") << "Peace &amp; Love" << "Peace & Love";
107+ QTest::newRow("apostrophe") << "Kick him while he&apos;s down" << "Kick him while he's down";
108+ QTest::newRow("mixed tags") << "<b>So broken</i>" << "So broken";
109+}
110+
111+void TestNotifications::testTextFilter() {
112+ const int timeout = 1000;
113+
114+ Notification n(new Notification(1, timeout, Notification::Low, "notification", Notification::Ephemeral));
115+
116+ QFETCH(QString, string);
117+ QFETCH(QString, result);
118+ n.setSummary(string);
119+ QCOMPARE(n.getSummary(), result);
120+ n.setBody(string);
121+ QCOMPARE(n.getBody(), result);
122+}
123+
124 QTEST_MAIN(TestNotifications)
125 #include "notificationtest.moc"

Subscribers

People subscribed via source and target branches

to all changes: