aboutsummaryrefslogtreecommitdiffstats
path: root/src/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 /src/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 'src/qml')
-rw-r--r--src/qml/jsruntime/qv4urlobject.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4urlobject.cpp b/src/qml/jsruntime/qv4urlobject.cpp
index c63e71ea46..0a55a1d876 100644
--- a/src/qml/jsruntime/qv4urlobject.cpp
+++ b/src/qml/jsruntime/qv4urlobject.cpp
@@ -167,7 +167,7 @@ void UrlObject::setUrl(const QUrl &url)
d()->port.set(engine(),
engine()->newString(url.port() == -1 ? QLatin1String("")
: QString::number(url.port())));
- d()->protocol.set(engine(), engine()->newString(url.scheme()));
+ d()->protocol.set(engine(), engine()->newString(url.scheme() + QLatin1Char(':')));
d()->search.set(engine(), engine()->newString(url.query()));
d()->username.set(engine(), engine()->newString(url.userName()));
@@ -222,15 +222,23 @@ bool UrlObject::setPort(QString port)
return true;
}
-bool UrlObject::setProtocol(QString protocol)
+bool UrlObject::setProtocol(QString protocolOrScheme)
{
QUrl url = toQUrl();
- url.setScheme(protocol);
+ // If there is one or several ':' in the protocolOrScheme,
+ // everything from the first colon is removed.
+
+ qsizetype firstColonPos = protocolOrScheme.indexOf(QLatin1Char(':'));
+
+ if (firstColonPos != -1)
+ protocolOrScheme.truncate(firstColonPos);
+
+ url.setScheme(protocolOrScheme);
if (!url.isValid())
return false;
- d()->protocol.set(engine(), engine()->newString(url.scheme()));
+ d()->protocol.set(engine(), engine()->newString(url.scheme() + QLatin1Char(':')));
d()->href.set(engine(), engine()->newString(url.toString()));
updateOrigin();