on xenial help sign in
Fix bug #1536296
434b6afAlbert Astals Cid
plugins/Dash/CardCreator.js+18
@@ -373,9 +373,27 @@ var kAudioProgressBarCode = 'CardAudioProgress { \n\
373 color: %3; \n\
373 color: %3; \n\
374 }';
374 }';
375
375
376+function evil_param(object) {
377+ for (var x in object) {
378+ if (typeof object[x] === "object" && evil_param(object[x]))
379+ return true;
380+
381+ if (typeof object[x] === "string" && object[x].match(/"(?:[^"\\]|\\.)*"/) != null)
382+ return true;
383+ }
384+
385+ return false;
386+}
387+
376function cardString(template, components) {
388function cardString(template, components) {
377 var code;
389 var code;
378
390
391+ if (evil_param(template))
392+ return "";
393+
394+ if (evil_param(components))
395+ return "";
396+
379 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
397 var templateInteractive = (template == null ? true : (template["non-interactive"] !== undefined ? !template["non-interactive"] : true)) ? "true" : "false";
380
398
381 code = 'AbstractButton { \n\
399 code = 'AbstractButton { \n\
tests/plugins/Dash/cardcreator/10.tstnew file+2
@@ -0,0 +1,2 @@
1+template: {"card-background":{"elements":["#E9E9E9"],"type":"color"},"card-layout":"vertical","card-size":"medium","category-layout":"grid","collapsed-rows":2, "card-background": { "type": "color", "elements": [ "\" : \"\";} Item { } function moo() { return true ? \"" ] } }
2+components: {"art":{"aspect-ratio":1},"background":{"field":"background"},"mascot":{"field":"icon"},"subtitle":{"field":"author"},"title":{"field":"title"},"attributes":{}}
tests/plugins/Dash/cardcreator/3.res+1
@@ -86,6 +86,7 @@ Item {
86 asynchronous: root.asynchronous;
86 asynchronous: root.asynchronous;
87 width: root.width;
87 width: root.width;
88 height: width / artShape.aspect;
88 height: width / artShape.aspect;
89+ onStatusChanged: if (status === Image.Error) source = "IHAVE\"ESCAPED\"QUOTES\"";
89 }
90 }
90 }
91 }
91 }
92 }
tests/plugins/Dash/cardcreator/3.tst+1−1
@@ -1,3 +1,3 @@
1template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
1template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
2−components: {"art":{"aspect-ratio":0.75,"field":"art"},"subtitle":{"field":"price"},"title":{"field":"title"},"attributes":{}}
2+components: {"art":{"aspect-ratio":0.75,"field":"art","fallback":"IHAVE\\\"ESCAPED\\\"QUOTES\\\""},"subtitle":{"field":"price"},"title":{"field":"title"},"attributes":{}}
3result: 3.res
3result: 3.res
tests/plugins/Dash/cardcreatortest.cpp+23−21
@@ -63,7 +63,7 @@ private Q_SLOTS:
63
63
64 QVERIFY(lines[0].startsWith(templateString));
64 QVERIFY(lines[0].startsWith(templateString));
65 QVERIFY(lines[1].startsWith(componentsString));
65 QVERIFY(lines[1].startsWith(componentsString));
66− QVERIFY(lines[2].startsWith(resultString));
66+
67 const QString templateJSON = lines[0].mid(templateString.length());
67 const QString templateJSON = lines[0].mid(templateString.length());
68 const QString componentsJSON = lines[1].mid(componentsString.length());
68 const QString componentsJSON = lines[1].mid(componentsString.length());
69 const QString resultFileName = lines[2].mid(resultString.length());
69 const QString resultFileName = lines[2].mid(resultString.length());
@@ -71,30 +71,32 @@ private Q_SLOTS:
71 QVariant cardStringResult;
71 QVariant cardStringResult;
72 QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
72 QMetaObject::invokeMethod(view->rootObject(), "cardString", Q_RETURN_ARG(QVariant, cardStringResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
73
73
74+ if (!resultFileName.isEmpty()) {
74− QFile testResultFile(testDirPath + resultFileName);
75+ QFile testResultFile(testDirPath + resultFileName);
75− QVERIFY(testResultFile.open(QIODevice::ReadOnly));
76+ QVERIFY(testResultFile.open(QIODevice::ReadOnly));
76− QTextStream ts2(&testResultFile);
77+ QTextStream ts2(&testResultFile);
77−
78+
78− // Record failed results to /tmp
79+ // Record failed results to /tmp
79− const QString executedResult = cardStringResult.toString();
80+ const QString executedResult = cardStringResult.toString();
80− QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
81+ QTemporaryFile tmpFile(QDir::tempPath() + QDir::separator() + "testCardCreatorFailedResultXXXXXX");
81− tmpFile.open();
82+ tmpFile.open();
82− tmpFile.setAutoRemove(false);
83+ tmpFile.setAutoRemove(false);
83− tmpFile.write(executedResult.toUtf8().constData());
84+ tmpFile.write(executedResult.toUtf8().constData());
84−
85+
85− // Line by line comparison
86+ // Line by line comparison
86− const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
87+ const QStringList expectedLines = ts2.readAll().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
87− const QStringList cardStringResultLines = cardStringResult.toString().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
88+ const QStringList cardStringResultLines = cardStringResult.toString().trimmed().replace(QRegExp("\n\\s*\n"),"\n").split("\n");
88− for (int i = 0; i < expectedLines.size(); ++i) {
89+ for (int i = 0; i < expectedLines.size(); ++i) {
89− QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
90+ QCOMPARE(cardStringResultLines[i].simplified(), expectedLines[i].simplified());
91+ }
92+
93+ // Remove the result if it passed
94+ tmpFile.setAutoRemove(true);
90 }
95 }
91
96
92− // Remove the result if it passed
93− tmpFile.setAutoRemove(true);
94−
95 QVariant createCardComponentResult;
97 QVariant createCardComponentResult;
96 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
98 QMetaObject::invokeMethod(view->rootObject(), "createCardComponent", Q_RETURN_ARG(QVariant, createCardComponentResult), Q_ARG(QVariant, templateJSON), Q_ARG(QVariant, componentsJSON));
97− QVERIFY(createCardComponentResult.toBool());
99+ QCOMPARE(createCardComponentResult.toBool(), !resultFileName.isEmpty());
98 }
100 }
99 }
101 }
100
102