aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
diff options
context:
space:
mode:
authorLeticia Valladares <leticia.valladares.fernandez@qt.io>2022-06-02 11:01:03 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2022-09-13 07:16:01 +0000
commit3571770380257c50471ce03b9448804622871375 (patch)
treea3e5eab426731a508cd20cff707426e8bfa54119 /tests/auto/qml
parent9cd41298c115d5d82cadbef315eb876d860317aa (diff)
UrlObject: Add colon after scheme
This change adds a colon after scheme in methods 'setProtocol' and 'setUrl' on its protocol line. Likewise, this includes a test called 'colonAfterProtocol' to check if colons were correctly added by using different schemes: ftp, http and https, or if colons were removed when setting the scheme (i.e. from protocol 'ftp:', 'ftp:http:' or 'ftp:::' to 'ftp'). Fixes: QTBUG-103746 Change-Id: I8f847bedd23e476e0ae7901a2f3f3963da3ca04d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit c61075d2e0049b3c92556c7221e38ef1122118b6) Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp2
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp60
2 files changed, 57 insertions, 5 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 4982085172..f08d247148 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -5421,7 +5421,7 @@ void tst_QJSEngine::urlObject()
check(QStringLiteral("href"), url.toString());
check(QStringLiteral("origin"), QStringLiteral("http://example.com:777"));
- check(QStringLiteral("protocol"), url.scheme());
+ check(QStringLiteral("protocol"), url.scheme() + QLatin1Char(':'));
check(QStringLiteral("username"), url.userName());
check(QStringLiteral("password"), url.password());
check(QStringLiteral("host"), url.host() + u':' + QString::number(url.port()));
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index c68fc1019f..4beedc4e88 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -411,6 +411,7 @@ private slots:
void urlConstruction();
void urlPropertyInvalid();
void urlPropertySet();
+ void colonAfterProtocol();
void urlSearchParamsConstruction();
void urlSearchParamsMethods();
void variantConversionMethod();
@@ -9629,7 +9630,7 @@ void tst_qqmlecmascript::urlConstruction()
QV4::UrlObject *validUrl = ret->as<QV4::UrlObject>();
QVERIFY(validUrl != nullptr);
- QCOMPARE(validUrl->protocol(), "https");
+ QCOMPARE(validUrl->protocol(), "https:");
QCOMPARE(validUrl->hostname(), "example.com");
QCOMPARE(validUrl->username(), "username");
QCOMPARE(validUrl->password(), "password");
@@ -9649,7 +9650,7 @@ void tst_qqmlecmascript::urlConstruction()
QV4::UrlObject *validRelativeUrl = retRel->as<QV4::UrlObject>();
QVERIFY(validRelativeUrl != nullptr);
- QCOMPARE(validRelativeUrl->protocol(), "https");
+ QCOMPARE(validRelativeUrl->protocol(), "https:");
QCOMPARE(validRelativeUrl->hostname(), "example.com");
QCOMPARE(validRelativeUrl->username(), "username");
QCOMPARE(validRelativeUrl->password(), "password");
@@ -9709,7 +9710,7 @@ void tst_qqmlecmascript::urlPropertySet()
// protocol
QVERIFY(EVALUATE("this.url.protocol = 'https';"));
- QCOMPARE(url->protocol(), "https");
+ QCOMPARE(url->protocol(), "https:");
QCOMPARE(url->href(), "https://localhost/a/b/c");
QCOMPARE(url->origin(), "https://localhost");
@@ -9772,7 +9773,7 @@ void tst_qqmlecmascript::urlPropertySet()
"this.url.href = "
"'https://username:password@example.com:1234/path/to/something?search=value#hash';"));
- QCOMPARE(url->protocol(), "https");
+ QCOMPARE(url->protocol(), "https:");
QCOMPARE(url->hostname(), "example.com");
QCOMPARE(url->username(), "username");
QCOMPARE(url->password(), "password");
@@ -9786,6 +9787,57 @@ void tst_qqmlecmascript::urlPropertySet()
QCOMPARE(url->hash(), "#hash");
}
+void tst_qqmlecmascript::colonAfterProtocol()
+{
+ QQmlEngine qmlengine;
+
+ QObject *o = new QObject(&qmlengine);
+
+ QV4::ExecutionEngine *engine = qmlengine.handle();
+ QV4::Scope scope(engine);
+
+ QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(engine, o));
+
+ QV4::ScopedValue ret(scope, EVALUATE("this.url = new URL('http://localhost/a/b/c');"));
+ QV4::UrlObject *url = ret->as<QV4::UrlObject>();
+ QVERIFY(url != nullptr);
+
+ // https without colon
+ QVERIFY(EVALUATE("this.url.protocol = 'https';"));
+ QCOMPARE(url->protocol(), "https:");
+ QCOMPARE(url->href(), "https://localhost/a/b/c");
+ QCOMPARE(url->origin(), "https://localhost");
+
+ QV4::ScopedValue retHttps(scope, EVALUATE("this.url = new URL('https://localhost/a/b/c');"));
+ QV4::UrlObject *urlHttps = retHttps->as<QV4::UrlObject>();
+ QVERIFY(urlHttps != nullptr);
+
+ // ftp with a colon
+ QVERIFY(EVALUATE("this.url.protocol = 'ftp:';"));
+ QCOMPARE(urlHttps->protocol(), "ftp:");
+ QCOMPARE(urlHttps->href(), "ftp://localhost/a/b/c");
+ QCOMPARE(urlHttps->origin(), "ftp://localhost");
+
+ QV4::ScopedValue retHttp(scope, EVALUATE("this.url = new URL('http://localhost/a/b/c');"));
+ QV4::UrlObject *ftpHttps = retHttp->as<QV4::UrlObject>();
+ QVERIFY(ftpHttps != nullptr);
+
+ // ftp with three colons
+ QVERIFY(EVALUATE("this.url.protocol = 'ftp:::';"));
+ QCOMPARE(ftpHttps->protocol(), "ftp:");
+ QCOMPARE(ftpHttps->href(), "ftp://localhost/a/b/c");
+ QCOMPARE(ftpHttps->origin(), "ftp://localhost");
+
+ QV4::ScopedValue retWss(scope, EVALUATE("this.url = new URL('wss://localhost/a/b/c');"));
+ QV4::UrlObject *urlFtpHttp = retWss->as<QV4::UrlObject>();
+ QVERIFY(urlFtpHttp != nullptr);
+
+ // ftp and http with a colon inbetween
+ QVERIFY(EVALUATE("this.url.protocol = 'ftp:http:';"));
+ QCOMPARE(urlFtpHttp->protocol(), "ftp:");
+ QCOMPARE(urlFtpHttp->href(), "ftp://localhost/a/b/c");
+ QCOMPARE(urlFtpHttp->origin(), "ftp://localhost");
+}
void tst_qqmlecmascript::urlSearchParamsConstruction()
{