From d264a0dab80553335b1c73f1d1ba393b79f1e18e Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Mon, 10 Oct 2016 16:16:52 +0200 Subject: [PATCH] Fix Url Query formatting fixes #12883 --- lib/remote/url.cpp | 15 ++++++++++++--- test/remote-url.cpp | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp index 78119f053..77074af3c 100644 --- a/lib/remote/url.cpp +++ b/lib/remote/url.cpp @@ -257,17 +257,26 @@ String Url::Format(bool print_credentials) const else param += "&"; + // Just one (or one empty) value + if (kv.second.size() == 1) { + param += key; + param += kv.second[0].IsEmpty() ? + String() : "=" + Utility::EscapeString(kv.second[0], ACQUERY_ENCODE, false); + continue; + } + + // Array String temp; for (const String s : kv.second) { if (!temp.IsEmpty()) temp += "&"; temp += key; - if (kv.second.size() > 1) temp += "[]"; - temp += "=" + Utility::EscapeString(s, ACQUERY_ENCODE, false); + if (!s.IsEmpty()) + temp += "=" + Utility::EscapeString(s, ACQUERY_ENCODE, false); } param += temp; } @@ -375,7 +384,7 @@ bool Url::ParseQuery(const String& query) String key = token.SubStr(0, pHelper); String value = Empty; - if (pHelper != token.GetLength() - 1) + if (pHelper != String::NPos && pHelper != token.GetLength() - 1) value = token.SubStr(pHelper+1); if (!ValidateToken(value, ACQUERY)) diff --git a/test/remote-url.cpp b/test/remote-url.cpp index b8d7c5fb7..5dc02bc7e 100644 --- a/test/remote-url.cpp +++ b/test/remote-url.cpp @@ -91,6 +91,7 @@ BOOST_AUTO_TEST_CASE(format) url = new Url("/foo/bar/index.php?blaka"); BOOST_CHECK(new Url(url->Format())); + BOOST_CHECK(url->Format() == "/foo/bar/index.php?blaka"); url = new Url("/"); BOOST_CHECK(url->Format() == "/");