From 6053fe2e1f8fa32db37d93e0b8456b53eca8a39c Mon Sep 17 00:00:00 2001 From: Jonathan Robie Date: Thu, 16 Sep 2010 14:52:37 +0000 Subject: Fixes parsing problem with empty lists ('[]') in addresses, which previously raised an exception and leaked the memory associated with the AddressImpl. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@997771 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/messaging/AddressParser.cpp | 9 +++++++-- qpid/cpp/src/qpid/messaging/AddressParser.h | 1 + qpid/cpp/src/tests/Address.cpp | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'qpid/cpp') diff --git a/qpid/cpp/src/qpid/messaging/AddressParser.cpp b/qpid/cpp/src/qpid/messaging/AddressParser.cpp index b6d5f764cf..c34c9c0f56 100644 --- a/qpid/cpp/src/qpid/messaging/AddressParser.cpp +++ b/qpid/cpp/src/qpid/messaging/AddressParser.cpp @@ -94,7 +94,7 @@ bool AddressParser::readList(Variant& value) void AddressParser::readListItems(Variant::List& list) { Variant item; - while (readValue(item)) { + while (readValueIfExists(item)) { list.push_back(item); if (!readChar(',')) break; } @@ -138,9 +138,14 @@ bool AddressParser::readKey(std::string& key) } bool AddressParser::readValue(Variant& value) +{ + return readValueIfExists(value) || error("Expected value"); +} + +bool AddressParser::readValueIfExists(Variant& value) { return readSimpleValue(value) || readQuotedValue(value) || - readMap(value) || readList(value) || error("Expected value"); + readMap(value) || readList(value); } bool AddressParser::readString(std::string& value, char delimiter) diff --git a/qpid/cpp/src/qpid/messaging/AddressParser.h b/qpid/cpp/src/qpid/messaging/AddressParser.h index a3f41eb04d..1635331d19 100644 --- a/qpid/cpp/src/qpid/messaging/AddressParser.h +++ b/qpid/cpp/src/qpid/messaging/AddressParser.h @@ -46,6 +46,7 @@ class AddressParser bool readSimpleValue(qpid::types::Variant& word); bool readKey(std::string& key); bool readValue(qpid::types::Variant& value); + bool readValueIfExists(qpid::types::Variant& value); bool readKeyValuePair(qpid::types::Variant::Map& map); bool readMap(qpid::types::Variant& value); bool readList(qpid::types::Variant& value); diff --git a/qpid/cpp/src/tests/Address.cpp b/qpid/cpp/src/tests/Address.cpp index a0b87e25af..32d14bb4b8 100644 --- a/qpid/cpp/src/tests/Address.cpp +++ b/qpid/cpp/src/tests/Address.cpp @@ -87,6 +87,24 @@ QPID_AUTO_TEST_CASE(testParseOptionsWithList) BOOST_CHECK_EQUAL((uint16_t) 101, address.getOptions()["x"].asInt64()); } +QPID_AUTO_TEST_CASE(testParseOptionsWithEmptyList) +{ + Address address("my-topic; {a:[], x:101}"); + BOOST_CHECK_EQUAL(std::string("my-topic"), address.getName()); + Variant::List& list = address.getOptions()["a"].asList(); + BOOST_CHECK_EQUAL(list.size(), 0); + BOOST_CHECK_EQUAL((uint16_t) 101, address.getOptions()["x"].asInt64()); +} + +QPID_AUTO_TEST_CASE(testParseOptionsWithEmptyMap) +{ + Address address("my-topic; {a:{}, x:101}"); + BOOST_CHECK_EQUAL(std::string("my-topic"), address.getName()); + Variant::Map& map = address.getOptions()["a"].asMap(); + BOOST_CHECK_EQUAL(map.size(), 0); + BOOST_CHECK_EQUAL((uint16_t) 101, address.getOptions()["x"].asInt64()); +} + QPID_AUTO_TEST_CASE(testParseQuotedNameAndSubject) { Address address("'my topic with / in it'/'my subject with ; in it'"); -- cgit v1.2.1