aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-02-27 17:07:29 +0100
committerSona Kurazyan <sona.kurazyan@qt.io>2019-03-06 10:01:08 +0000
commitd9d26033bb3945cf69654b505f85f9786e42eade (patch)
treede2a522d4a61b70abd2367648d4e7025af576e69
parent09d1d3bf20acfdb194f91e38ebfa67cc641f0119 (diff)
Fix URL adjustment for URLs with no schemev5.13.0-beta1
Prepend the "scheme://" part a to URL only if it is relative and doesn't have a host. Non-relative URLs having a host already contain the "://" part. Change-Id: If2ac3db4f2eb0d18ffa1893415f44b9d2c85db26 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/coap/qcoapclient.cpp2
-rw-r--r--src/coap/qcoaprequest.cpp7
-rw-r--r--tests/auto/qcoaprequest/tst_qcoaprequest.cpp8
3 files changed, 13 insertions, 4 deletions
diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp
index e4fd763..09e171c 100644
--- a/src/coap/qcoapclient.cpp
+++ b/src/coap/qcoapclient.cpp
@@ -429,8 +429,6 @@ QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group,
QUrl discoveryUrl;
discoveryUrl.setHost(base);
- QString scheme = d->connection->isSecure() ? QStringLiteral("coaps") : QStringLiteral("coap");
- discoveryUrl.setScheme(scheme);
discoveryUrl.setPath(discoveryPath);
QCoapRequest request(discoveryUrl);
diff --git a/src/coap/qcoaprequest.cpp b/src/coap/qcoaprequest.cpp
index e23c806..f3fdca8 100644
--- a/src/coap/qcoaprequest.cpp
+++ b/src/coap/qcoaprequest.cpp
@@ -295,10 +295,13 @@ QUrl QCoapRequest::adjustedUrl(const QUrl &url, bool secure)
QUrl finalizedUrl = url;
const auto scheme = secure ? CoapSecureScheme : CoapScheme;
- if (url.isRelative())
+ if (url.host().isEmpty() && url.isRelative()) {
+ // In some cases host address is mistaken for part of the relative path,
+ // prepending the scheme fixes this.
finalizedUrl = url.toString().prepend(scheme + QLatin1String("://"));
- else if (url.scheme().isEmpty())
+ } else if (url.scheme().isEmpty()) {
finalizedUrl.setScheme(scheme);
+ }
if (url.port() == -1) {
const auto port = secure ? QtCoap::DefaultSecurePort : QtCoap::DefaultPort;
diff --git a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
index 1a5c413..5ac0b6d 100644
--- a/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
+++ b/tests/auto/qcoaprequest/tst_qcoaprequest.cpp
@@ -88,6 +88,14 @@ void tst_QCoapRequest::adjustUrl_data()
<< QUrl("coap://vs0.inf.ethz.ch:5683/test") << false;
QTest::newRow("no_scheme_no_port_secure") << QUrl("vs0.inf.ethz.ch/test")
<< QUrl("coaps://vs0.inf.ethz.ch:5684/test") << true;
+
+ QUrl ipv6Host;
+ ipv6Host.setHost("::1");
+ ipv6Host.setPath("/path");
+ QTest::newRow("no_scheme_no_port_ipv6") << ipv6Host << QUrl("coap://[::1]:5683/path")
+ << false;
+ QTest::newRow("no_scheme_no_port_ipv6_secure") << ipv6Host << QUrl("coaps://[::1]:5684/path")
+ << true;
}
void tst_QCoapRequest::adjustUrl()