summaryrefslogtreecommitdiff
path: root/qpid/cpp
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
commit6053fe2e1f8fa32db37d93e0b8456b53eca8a39c (patch)
tree3af6892f7e49cac15afdf21985fdee40aae1d17d /qpid/cpp
parent8f2a0309176e62ef5d399243ebca2c6a6defc7d5 (diff)
downloadqpid-python-6053fe2e1f8fa32db37d93e0b8456b53eca8a39c.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@997771 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp')
-rw-r--r--qpid/cpp/src/qpid/messaging/AddressParser.cpp9
-rw-r--r--qpid/cpp/src/qpid/messaging/AddressParser.h1
-rw-r--r--qpid/cpp/src/tests/Address.cpp18
3 files changed, 26 insertions, 2 deletions
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;
}
@@ -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/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'");