aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorLeticia Valladares <leticia.valladares.fernandez@qt.io>2022-06-02 11:01:03 +0200
committerLeticia Valladares <leticia.valladares.fernandez@qt.io>2022-07-14 23:59:21 +0200
commitc61075d2e0049b3c92556c7221e38ef1122118b6 (patch)
treedf0cb4d9f168f020c2b4caab6435ed742fe43645 /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parent0063be4ba100b39a781b13b1c16b608a681ea152 (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>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp60
1 files changed, 56 insertions, 4 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 55994b51c0..9aacb05043 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -386,6 +386,7 @@ private slots:
void urlConstruction();
void urlPropertyInvalid();
void urlPropertySet();
+ void colonAfterProtocol();
void urlSearchParamsConstruction();
void urlSearchParamsMethods();
void variantConversionMethod();
@@ -9556,7 +9557,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");
@@ -9576,7 +9577,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");
@@ -9636,7 +9637,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");
@@ -9699,7 +9700,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");
@@ -9713,6 +9714,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()
{