[icinga-checkins] icinga.org: icinga2/feature/check_nscp-12874: Fix Url query without values

git at icinga.org git at icinga.org
Fri Oct 14 13:38:58 CEST 2016


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

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

Fix Url query without values

fixes #12883

---

 lib/remote/url.cpp |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/remote/url.cpp b/lib/remote/url.cpp
index 78119f0..fff11ad 100644
--- a/lib/remote/url.cpp
+++ b/lib/remote/url.cpp
@@ -257,6 +257,14 @@ 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() ? Empty : "=" + Utility::EscapeString(kv.second[0], ACQUERY_ENCODE, false);
+				continue;
+			}
+
+			// Array
 			String temp;
 			for (const String s : kv.second) {
 				if (!temp.IsEmpty())
@@ -267,7 +275,8 @@ String Url::Format(bool print_credentials) const
 				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 != token.NPos && pHelper != token.GetLength() - 1)
 			value = token.SubStr(pHelper+1);
 
 		if (!ValidateToken(value, ACQUERY))



More information about the icinga-checkins mailing list