aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-01-16 11:05:23 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-18 01:37:30 +0100
commit3aa53b8bc383ebcdf8dc922b2670170ec012949f (patch)
tree26181d69c9cdb5a2bbd61a3c99b97523352cf08c /tests/auto
parent52c1d7a994216f0b37ac04a2fea4337bc0c7550b (diff)
Allow QML URLs to contain pre-encoded octets
Use QUrl Tolerant parsing mode to permit user-supplied URLs to contain pre-encoded octets which are not mangled by string conversion. Task-number: QTBUG-22756 Change-Id: I4b160b04340b95221d1eb3336bda8c0b38d2e232 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/urlListProperty.qml41
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.2.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp38
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml2
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp108
6 files changed, 201 insertions, 2 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/urlListProperty.qml b/tests/auto/declarative/qdeclarativeecmascript/data/urlListProperty.qml
new file mode 100644
index 0000000000..eeb0815f09
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/urlListProperty.qml
@@ -0,0 +1,41 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Item {
+ // single url assignment to url list property
+ MySequenceConversionObject {
+ id: msco1
+ objectName: "msco1"
+ }
+
+ // single url binding to url list property
+ MySequenceConversionObject {
+ id: msco2
+ objectName: "msco2"
+ urlListProperty: "http://qt-project.org/?get%3cDATA%3e";
+ }
+
+ // multiple url assignment to url list property
+ MySequenceConversionObject {
+ id: msco3
+ objectName: "msco3"
+ }
+
+ // multiple url binding to url list property
+ MySequenceConversionObject {
+ id: msco4
+ objectName: "msco4"
+ urlListProperty: [
+ "http://qt-project.org/?get%3cDATA%3e",
+ "http://qt-project.org/?get%3cDATA%3e"
+ ];
+ }
+
+ Component.onCompleted: {
+ msco1.urlListProperty = "http://qt-project.org/?get%3cDATA%3e";
+ msco3.urlListProperty = [
+ "http://qt-project.org/?get%3cDATA%3e",
+ "http://qt-project.org/?get%3cDATA%3e"
+ ];
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.2.qml
new file mode 100644
index 0000000000..0e8bdaec96
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/urlProperty.2.qml
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+MyQmlObject {
+ property bool result
+ stringProperty: "http://example.org"
+ urlProperty: stringProperty + "/?get%3cDATA%3e"
+ value: urlProperty == stringProperty + "/?get%3cDATA%3e"
+ result: urlProperty == urlProperty
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 5f1f44e278..18c56af6e2 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -213,6 +213,8 @@ private slots:
void aliasToCompositeElement();
void realToInt();
void urlProperty();
+ void urlPropertyWithEncoding();
+ void urlListPropertyWithEncoding();
void dynamicString();
void include();
void signalHandlers();
@@ -5519,6 +5521,42 @@ void tst_qdeclarativeecmascript::urlProperty()
}
}
+void tst_qdeclarativeecmascript::urlPropertyWithEncoding()
+{
+ {
+ QDeclarativeComponent component(&engine, testFileUrl("urlProperty.2.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QVERIFY(object != 0);
+ object->setStringProperty("http://qt-project.org");
+ QUrl encoded;
+ encoded.setEncodedUrl("http://qt-project.org/?get%3cDATA%3e", QUrl::TolerantMode);
+ QCOMPARE(object->urlProperty(), encoded);
+ QCOMPARE(object->value(), 0); // Interpreting URL as string yields canonicalised version
+ QCOMPARE(object->property("result").toBool(), true);
+ }
+}
+
+void tst_qdeclarativeecmascript::urlListPropertyWithEncoding()
+{
+ {
+ QDeclarativeComponent component(&engine, testFileUrl("urlListProperty.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ MySequenceConversionObject *msco1 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco1"));
+ MySequenceConversionObject *msco2 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco2"));
+ MySequenceConversionObject *msco3 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco3"));
+ MySequenceConversionObject *msco4 = object->findChild<MySequenceConversionObject *>(QLatin1String("msco4"));
+ QVERIFY(msco1 != 0 && msco2 != 0 && msco3 != 0 && msco4 != 0);
+ QUrl encoded;
+ encoded.setEncodedUrl("http://qt-project.org/?get%3cDATA%3e", QUrl::TolerantMode);
+ QCOMPARE(msco1->urlListProperty(), (QList<QUrl>() << encoded));
+ QCOMPARE(msco2->urlListProperty(), (QList<QUrl>() << encoded));
+ QCOMPARE(msco3->urlListProperty(), (QList<QUrl>() << encoded << encoded));
+ QCOMPARE(msco4->urlListProperty(), (QList<QUrl>() << encoded << encoded));
+ delete object;
+ }
+}
+
void tst_qdeclarativeecmascript::dynamicString()
{
QDeclarativeComponent component(&engine, testFileUrl("dynamicString.qml"));
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
index 2313499d19..28a340128d 100644
--- a/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
+++ b/tests/auto/declarative/qdeclarativelanguage/data/assignBasicTypes.qml
@@ -22,7 +22,7 @@ MyTypeObject {
variantProperty: "Hello World!"
vectorProperty: "10,1,2.2"
vector4Property: "10,1,2.2,2.3"
- urlProperty: "main.qml"
+ urlProperty: "main.qml?with%3cencoded%3edata"
objectProperty: MyTypeObject { intProperty: 8 }
}
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index 7af60e4496..65b5f61022 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -580,7 +580,9 @@ void tst_qdeclarativelanguage::assignBasicTypes()
QCOMPARE(object->variantProperty(), QVariant("Hello World!"));
QCOMPARE(object->vectorProperty(), QVector3D(10, 1, 2.2));
QCOMPARE(object->vector4Property(), QVector4D(10, 1, 2.2, 2.3));
- QCOMPARE(object->urlProperty(), component.url().resolved(QUrl("main.qml")));
+ QUrl encoded;
+ encoded.setEncodedUrl("main.qml?with%3cencoded%3edata", QUrl::TolerantMode);
+ QCOMPARE(object->urlProperty(), component.url().resolved(encoded));
QVERIFY(object->objectProperty() != 0);
MyTypeObject *child = qobject_cast<MyTypeObject *>(object->objectProperty());
QVERIFY(child != 0);
diff --git a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
index bf927a74fc..348c2582c0 100644
--- a/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
+++ b/tests/auto/declarative/qdeclarativeproperty/tst_qdeclarativeproperty.cpp
@@ -49,6 +49,7 @@
#include <QtCore/qdir.h>
#include "../../shared/util.h"
+#include <QDebug>
class MyQmlObject : public QObject
{
Q_OBJECT
@@ -120,6 +121,9 @@ private slots:
//writeToReadOnly();
+ void urlHandling_data();
+ void urlHandling();
+
// Bugs
void crashOnValueProperty();
void aliasPropertyBindings();
@@ -1338,6 +1342,110 @@ void tst_qdeclarativeproperty::writeListToList()
QCOMPARE(container->children()->size(), 1);*/
}
+void tst_qdeclarativeproperty::urlHandling_data()
+{
+ QTest::addColumn<QByteArray>("input");
+ QTest::addColumn<QString>("scheme");
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QByteArray>("encoded");
+
+ QTest::newRow("unspecifiedFile")
+ << QByteArray("main.qml")
+ << QString("")
+ << QString("main.qml")
+ << QByteArray("main.qml");
+
+ QTest::newRow("specifiedFile")
+ << QByteArray("file:///main.qml")
+ << QString("file")
+ << QString("/main.qml")
+ << QByteArray("file:///main.qml");
+
+ QTest::newRow("httpFile")
+ << QByteArray("http://www.example.com/main.qml")
+ << QString("http")
+ << QString("/main.qml")
+ << QByteArray("http://www.example.com/main.qml");
+
+ QTest::newRow("pathFile")
+ << QByteArray("http://www.example.com/resources/main.qml")
+ << QString("http")
+ << QString("/resources/main.qml")
+ << QByteArray("http://www.example.com/resources/main.qml");
+
+ QTest::newRow("encodableName")
+ << QByteArray("http://www.example.com/main file.qml")
+ << QString("http")
+ << QString("/main file.qml")
+ << QByteArray("http://www.example.com/main%20file.qml");
+
+ QTest::newRow("preencodedName")
+ << QByteArray("http://www.example.com/resources%7cmain%20file.qml")
+ << QString("http")
+ << QString("/resources|main file.qml")
+ << QByteArray("http://www.example.com/resources%7cmain%20file.qml");
+
+ QTest::newRow("encodableQuery")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml&comment=now working?")
+ << QString("http")
+ << QString("/main.qml")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml&comment=now%20working?");
+
+ QTest::newRow("preencodedQuery")
+ << QByteArray("http://www.example.com/main.qml?type=text%2fqml&comment=now working%3f")
+ << QString("http")
+ << QString("/main.qml")
+ << QByteArray("http://www.example.com/main.qml?type=text%2fqml&comment=now%20working%3f");
+
+ QTest::newRow("encodableFragment")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml#start+30000|volume+50%")
+ << QString("http")
+ << QString("/main.qml")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml#start+30000%7Cvolume+50%25");
+
+ QTest::newRow("preencodedFragment")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml#start+30000%7cvolume%2b50%")
+ << QString("http")
+ << QString("/main.qml")
+ << QByteArray("http://www.example.com/main.qml?type=text/qml#start+30000%7cvolume%2b50%25");
+}
+
+void tst_qdeclarativeproperty::urlHandling()
+{
+ QFETCH(QByteArray, input);
+ QFETCH(QString, scheme);
+ QFETCH(QString, path);
+ QFETCH(QByteArray, encoded);
+
+ QString inputString(QString::fromUtf8(input));
+
+ {
+ PropertyObject o;
+ QDeclarativeProperty p(&o, "url");
+
+ // Test url written as QByteArray
+ QCOMPARE(p.write(input), true);
+ QUrl byteArrayResult(o.url());
+
+ QCOMPARE(byteArrayResult.scheme(), scheme);
+ QCOMPARE(byteArrayResult.path(), path);
+ QCOMPARE(byteArrayResult.toEncoded(), encoded);
+ }
+
+ {
+ PropertyObject o;
+ QDeclarativeProperty p(&o, "url");
+
+ // Test url written as QString
+ QCOMPARE(p.write(inputString), true);
+ QUrl stringResult(o.url());
+
+ QCOMPARE(stringResult.scheme(), scheme);
+ QCOMPARE(stringResult.path(), path);
+ QCOMPARE(stringResult.toEncoded(), encoded);
+ }
+}
+
void tst_qdeclarativeproperty::crashOnValueProperty()
{
QDeclarativeEngine *engine = new QDeclarativeEngine;