aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2020-07-03 11:50:06 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-07-03 13:47:04 +0200
commit256503fadf5a925933fc03980d7c878643b1fdca (patch)
treef6db8932c95afd0dae58120667f81d28c2012ff6
parentbc314b11b08cdc6ce035bcbe85f5b1c1acddafd7 (diff)
URL: Allow non-string parameters
Previously we only allowed string parameters as the first parameter of the URL constructor. This excluded types like url. The behavior of instead trying to convert the parameter to a string and then interpreting this as an url matches the specification more closely. Change-Id: I6ef8db9d8c0f238ba8c51b1023decdfcc1caad87 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4urlobject.cpp6
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp13
2 files changed, 14 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4urlobject.cpp b/src/qml/jsruntime/qv4urlobject.cpp
index 7e52c63248..6f9a9ecb69 100644
--- a/src/qml/jsruntime/qv4urlobject.cpp
+++ b/src/qml/jsruntime/qv4urlobject.cpp
@@ -659,12 +659,8 @@ ReturnedValue UrlCtor::virtualCallAsConstructor(const FunctionObject *that, cons
Scope scope(v4);
ScopedValue arg1(scope, argv[0]);
- String *arg1StringValue = arg1->stringValue();
- if (arg1StringValue == nullptr)
- return v4->throwTypeError(QLatin1String("Invalid parameter provided"));
-
- QString arg1String = arg1StringValue->toQString();
+ QString arg1String = arg1->toQString();
QString urlString;
if (argc == 2) {
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 9b750d5399..0865628061 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -335,6 +335,9 @@ private slots:
void qualifiedScopeInCustomParser();
void checkUncreatableNoReason();
+
+ void checkURLtoURLObject();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -5929,6 +5932,16 @@ void tst_qqmllanguage::checkUncreatableNoReason()
QCOMPARE(c.errors().first().description(), QString("Type cannot be created in QML."));
}
+void tst_qqmllanguage::checkURLtoURLObject()
+{
+ QQmlEngine engine;
+ QString qml = QString("import QtQuick 2.0\nItem { property url source: 'file:///foo/bar/'; "
+ "Component.onCompleted: { new URL(parent.source); } }");
+ QQmlComponent c(&engine);
+ c.setData(qml.toUtf8(), QUrl::fromLocalFile(QDir::currentPath()));
+ QCOMPARE(c.errors().count(), 0);
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"