summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Robie <jonathan@apache.org>2010-09-16 14:52:37 +0000
committerJonathan Robie <jonathan@apache.org>2010-09-16 14:52:37 +0000
commita15b7ff7ba6e7ccd85bdd0042dd7ea65d6840e99 (patch)
treea5b1321053b4b2bb92023de1a78eb3fdb473f4ca
parent01fda72abf335c795df091ae6ea6a0b3a22ec72f (diff)
downloadqpid-python-a15b7ff7ba6e7ccd85bdd0042dd7ea65d6840e99.tar.gz
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/qpid@997771 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/src/qpid/messaging/AddressParser.cpp9
-rw-r--r--cpp/src/qpid/messaging/AddressParser.h1
-rw-r--r--cpp/src/tests/Address.cpp18
3 files changed, 26 insertions, 2 deletions
diff --git a/cpp/src/qpid/messaging/AddressParser.cpp b/cpp/src/qpid/messaging/AddressParser.cpp
index b6d5f764cf..c34c9c0f56 100644
--- a/cpp/src/qpid/messaging/AddressParser.cpp
+++ b/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;
}
@@ -139,8 +139,13 @@ 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/cpp/src/qpid/messaging/AddressParser.h b/cpp/src/qpid/messaging/AddressParser.h
index a3f41eb04d..1635331d19 100644
--- a/cpp/src/qpid/messaging/AddressParser.h
+++ b/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/cpp/src/tests/Address.cpp b/cpp/src/tests/Address.cpp
index a0b87e25af..32d14bb4b8 100644
--- a/cpp/src/tests/Address.cpp
+++ b/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'");