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.
This commit is contained in:
Matt Broadstone 2014-09-12 08:15:34 -04:00
parent d7dbcb892c
commit dab2cfe08f
2 changed files with 4 additions and 2 deletions

View File

@ -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());

View File

@ -134,6 +134,8 @@ void tst_QAMQPClient::validateUri_data()
QTest::addColumn<quint16>("expectedPort");
QTest::addColumn<QString>("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) << "";