From c61075d2e0049b3c92556c7221e38ef1122118b6 Mon Sep 17 00:00:00 2001 From: Leticia Valladares Date: Thu, 2 Jun 2022 11:01:03 +0200 Subject: 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 --- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 60 ++++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp') 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(); 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(); 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(); + 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(); + 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(); + 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(); + 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() { -- cgit v1.2.3