diff --git a/src/utility/url.cpp b/src/utility/url.cpp index d3c5445d..f9157d64 100644 --- a/src/utility/url.cpp +++ b/src/utility/url.cpp @@ -130,26 +130,23 @@ const string url::build() const oss << urlUtils::encode(m_path); } - const std::vector > params - = m_params.getPropertyList(); - if (!params.empty()) + if (!m_params.empty()) { if (m_path.empty()) oss << "/"; oss << "?"; - for (unsigned int i = 0 ; i < params.size() ; ++i) + for (std::map ::const_iterator it = m_params.begin() ; + it != m_params.end() ; ++it) { - const ref prop = params[i]; - - if (i != 0) + if (it != m_params.begin()) oss << "&"; - oss << urlUtils::encode(prop->getName()); + oss << urlUtils::encode((*it).first); oss << "="; - oss << urlUtils::encode(prop->getValue ()); + oss << urlUtils::encode((*it).second); } } @@ -267,7 +264,7 @@ void url::parse(const string& str) portNum = UNSPECIFIED_PORT; // Extract parameters - m_params.removeAllProperties(); + m_params.clear(); if (!params.empty()) { @@ -300,7 +297,7 @@ void url::parse(const string& str) name = urlUtils::decode(name); value = urlUtils::decode(value); - m_params.setProperty(name, value); + m_params[name] = value; if (pos != string::npos) ++pos; @@ -393,13 +390,13 @@ void url::setPath(const string& path) } -const propertySet& url::getParams() const +const std::map & url::getParams() const { return (m_params); } -propertySet& url::getParams() +std::map & url::getParams() { return (m_params); } diff --git a/tests/utility/urlTest.cpp b/tests/utility/urlTest.cpp index 6703ecd3..85991511 100644 --- a/tests/utility/urlTest.cpp +++ b/tests/utility/urlTest.cpp @@ -164,29 +164,29 @@ VMIME_TEST_SUITE_BEGIN(urlTest) vmime::utility::url u1("", ""); VASSERT_EQ("1.1", true, parseHelper(u1, "proto://host/path?p1=v1&p2=v2")); - VASSERT_EQ("1.2", "v1", u1.getParams().getProperty ("p1")); - VASSERT_EQ("1.3", "v2", u1.getParams().getProperty ("p2")); + VASSERT_EQ("1.2", "v1", u1.getParams()["p1"]); + VASSERT_EQ("1.3", "v2", u1.getParams()["p2"]); VASSERT_EQ("1.4", "/path", u1.getPath()); vmime::utility::url u2("", ""); VASSERT_EQ("2.1", true, parseHelper(u2, "proto://host/path?p1=v1&p2")); - VASSERT_EQ("2.2", "v1", u2.getParams().getProperty ("p1")); - VASSERT_EQ("2.3", "p2", u2.getParams().getProperty ("p2")); + VASSERT_EQ("2.2", "v1", u2.getParams()["p1"]); + VASSERT_EQ("2.3", "p2", u2.getParams()["p2"]); VASSERT_EQ("2.4", "/path", u2.getPath()); vmime::utility::url u3("", ""); VASSERT_EQ("3.1", true, parseHelper(u3, "proto://host/?p1=v1&p2=v2")); - VASSERT_EQ("3.2", "v1", u3.getParams().getProperty ("p1")); - VASSERT_EQ("3.3", "v2", u3.getParams().getProperty ("p2")); + VASSERT_EQ("3.2", "v1", u3.getParams()["p1"]); + VASSERT_EQ("3.3", "v2", u3.getParams()["p2"]); VASSERT_EQ("3.4", "", u3.getPath()); vmime::utility::url u4("", ""); VASSERT_EQ("4.1", true, parseHelper(u4, "proto://host/path?p1=%3D&%3D=v2")); - VASSERT_EQ("4.2", "=", u4.getParams().getProperty ("p1")); - VASSERT_EQ("4.3", "v2", u4.getParams().getProperty ("=")); + VASSERT_EQ("4.2", "=", u4.getParams()["p1"]); + VASSERT_EQ("4.3", "v2", u4.getParams()["="]); VASSERT_EQ("4.4", "/path", u4.getPath()); } @@ -211,14 +211,17 @@ VMIME_TEST_SUITE_BEGIN(urlTest) VASSERT_EQ("2", "proto://host", static_cast (u2)); vmime::utility::url u3("proto", "host"); - u3.getParams().setProperty("p1", "v1"); + u3.getParams()["p1"] = "v1"; VASSERT_EQ("3.1", "proto://host/?p1=v1", static_cast (u3)); - u3.getParams().setProperty("p2", "v2"); + u3.getParams()["p2"] = "v2"; VASSERT_EQ("3.2", "proto://host/?p1=v1&p2=v2", static_cast (u3)); - u3.getParams().setProperty("&", "="); - VASSERT_EQ("3.3", "proto://host/?p1=v1&p2=v2&%26=%3D", + + // Test special characters + u3.getParams().clear(); + u3.getParams()["&"] = "="; + VASSERT_EQ("3.3", "proto://host/?%26=%3D", static_cast (u3)); } diff --git a/vmime/utility/url.hpp b/vmime/utility/url.hpp index 825d2a32..84aba618 100644 --- a/vmime/utility/url.hpp +++ b/vmime/utility/url.hpp @@ -162,13 +162,13 @@ public: * * @return parameters */ - const propertySet& getParams() const; + const std::map & getParams() const; /** Return the parameters of the URL. * * @return parameters */ - propertySet& getParams(); + std::map & getParams(); /** Build a string URL from this object. */ @@ -196,7 +196,7 @@ private: string m_path; - propertySet m_params; + std::map m_params; };