[icinga-checkins] icinga.org: icinga2/feature/check_nscp-12874: Fix Url Query formatting

git at icinga.org git at icinga.org
Fri Oct 14 15:54:39 CEST 2016


Module: icinga2
Branch: feature/check_nscp-12874
Commit: 2ef6642144c9bd413f62e5e631b7a3dab569d7c0
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=2ef6642144c9bd413f62e5e631b7a3dab569d7c0

Author: Jean Flach <jean-marcel.flach at netways.de>
Date:   Mon Oct 10 16:16:52 2016 +0200

Fix Url Query formatting

fixes #12883

---

 lib/remote/url.cpp  |    6 +++---
 test/remote-url.cpp |    1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp
index 97d3230..77074af 100644
--- a/lib/remote/url.cpp
+++ b/lib/remote/url.cpp
@@ -260,7 +260,8 @@ String Url::Format(bool print_credentials) const
 			// Just one (or one empty) value
 			if (kv.second.size() == 1) {
 				param += key;
-				param += kv.second[0].IsEmpty() ? "" : "=" + Utility::EscapeString(kv.second[0], ACQUERY_ENCODE, false);
+				param += kv.second[0].IsEmpty() ?
+				    String() : "=" + Utility::EscapeString(kv.second[0], ACQUERY_ENCODE, false);
 				continue;
 			}
 
@@ -271,7 +272,6 @@ String Url::Format(bool print_credentials) const
 					temp += "&";
 
 				temp += key;
-
 				if (kv.second.size() > 1)
 					temp += "[]";
 
@@ -384,7 +384,7 @@ bool Url::ParseQuery(const String& query)
 		String key = token.SubStr(0, pHelper);
 		String value = Empty;
 
-		if (pHelper != token.NPos && 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 b8d7c5f..5dc02bc 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() == "/");



More information about the icinga-checkins mailing list