From dab2cfe08fce0f8776a87b0bcf06b5d84f046c7d Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Fri, 12 Sep 2014 08:15:34 -0400 Subject: [PATCH] fix parsing of connection strings with default vhost We should assume that a trailing slash at the end of a connection URI means to use the default vhost of /. This fixes issue #2. --- src/qamqpclient.cpp | 2 +- tests/auto/qamqpclient/tst_qamqpclient.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qamqpclient.cpp b/src/qamqpclient.cpp index e27f324..d4bee44 100644 --- a/src/qamqpclient.cpp +++ b/src/qamqpclient.cpp @@ -95,7 +95,7 @@ void ClientPrivate::parseConnectionString(const QString &uri) host = connectionString.host(); QString vhost = connectionString.path(); - if (vhost.startsWith("/")) + if (vhost.startsWith("/") && vhost.size() > 1) vhost = vhost.mid(1); #if QT_VERSION <= 0x050200 virtualHost = QUrl::fromPercentEncoding(vhost.toUtf8()); diff --git a/tests/auto/qamqpclient/tst_qamqpclient.cpp b/tests/auto/qamqpclient/tst_qamqpclient.cpp index 5a03e1a..d3a6284 100644 --- a/tests/auto/qamqpclient/tst_qamqpclient.cpp +++ b/tests/auto/qamqpclient/tst_qamqpclient.cpp @@ -134,6 +134,8 @@ void tst_QAMQPClient::validateUri_data() QTest::addColumn("expectedPort"); QTest::addColumn("expectedVirtualHost"); + QTest::newRow("default vhost") << "amqp://guest:guest@192.168.1.10:5672/" + << "guest" << "guest" << "192.168.1.10" << quint16(5672) << "/"; QTest::newRow("standard") << "amqp://user:pass@host:10000/vhost" << "user" << "pass" << "host" << quint16(10000) << "vhost"; #if QT_VERSION >= 0x040806 @@ -141,7 +143,7 @@ void tst_QAMQPClient::validateUri_data() << "usera" << "apass" << "hoast" << quint16(10000) << "v/host"; #endif QTest::newRow("empty") << "amqp://" << "" << "" << "" << quint16(AMQP_PORT) << ""; - QTest::newRow("empty2") << "amqp://:@/" << "" << "" << "" << quint16(AMQP_PORT) << ""; + QTest::newRow("empty2") << "amqp://:@/" << "" << "" << "" << quint16(AMQP_PORT) << "/"; QTest::newRow("onlyuser") << "amqp://user@" << "user" << "" << "" << quint16(AMQP_PORT) << ""; QTest::newRow("userpass") << "amqp://user:pass@" << "user" << "pass" << "" << quint16(AMQP_PORT) << ""; QTest::newRow("onlyhost") << "amqp://host" << "" << "" << "host" << quint16(AMQP_PORT) << "";