[icinga-checkins] icinga.org: icinga2/feature/filter-strings-11445: Fix: ConfigWriter:: EmitScope incorrectly quotes dictionary keys

git at icinga.org git at icinga.org
Wed Jun 22 16:43:44 CEST 2016


Module: icinga2
Branch: feature/filter-strings-11445
Commit: 428850a6b3e1ce24c9462f5ab296997856bc1bbf
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=428850a6b3e1ce24c9462f5ab296997856bc1bbf

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Jun 22 12:34:11 2016 +0200

Fix: ConfigWriter::EmitScope incorrectly quotes dictionary keys

fixes #12016

---

 lib/base/configwriter.cpp |   32 ++++++++++++++++++--------------
 lib/base/configwriter.hpp |    3 ++-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/base/configwriter.cpp b/lib/base/configwriter.cpp
index d0f8533..33be46e 100644
--- a/lib/base/configwriter.cpp
+++ b/lib/base/configwriter.cpp
@@ -74,7 +74,8 @@ void ConfigWriter::EmitArrayItems(std::ostream& fp, int indentLevel, const Array
 	}
 }
 
-void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val, const Array::Ptr& imports)
+void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val,
+    const Array::Ptr& imports, bool splitDot)
 {
 	fp << "{";
 
@@ -94,18 +95,21 @@ void ConfigWriter::EmitScope(std::ostream& fp, int indentLevel, const Dictionary
 		BOOST_FOREACH(const Dictionary::Pair& kv, val) {
 			fp << "\n";
 			EmitIndent(fp, indentLevel);
-			
-			std::vector<String> tokens;
-			boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));
-			
-			EmitIdentifier(fp, tokens[0], true);
-			
-			for (std::vector<String>::size_type i = 1; i < tokens.size(); i++) {
-				fp << "[";
-				EmitString(fp, tokens[i]);
-				fp << "]";
-			}
-			
+
+			if (splitDot) {
+				std::vector<String> tokens;
+				boost::algorithm::split(tokens, kv.first, boost::is_any_of("."));
+
+				EmitIdentifier(fp, tokens[0], true);
+
+				for (std::vector<String>::size_type i = 1; i < tokens.size(); i++) {
+					fp << "[";
+					EmitString(fp, tokens[i]);
+					fp << "]";
+				}
+			} else
+				EmitIdentifier(fp, kv.first, true);
+
 			fp << " = ";
 			EmitValue(fp, indentLevel + 1, kv.second);
 		}
@@ -189,7 +193,7 @@ void ConfigWriter::EmitConfigItem(std::ostream& fp, const String& type, const St
 		fp << " ignore_on_error";
 
 	fp << " ";
-	EmitScope(fp, 1, attrs, imports);
+	EmitScope(fp, 1, attrs, imports, true);
 }
 
 void ConfigWriter::EmitComment(std::ostream& fp, const String& text)
diff --git a/lib/base/configwriter.hpp b/lib/base/configwriter.hpp
index f7d5356..a32f286 100644
--- a/lib/base/configwriter.hpp
+++ b/lib/base/configwriter.hpp
@@ -60,7 +60,8 @@ public:
 	static void EmitEmpty(std::ostream& fp);
 	static void EmitArray(std::ostream& fp, int indentLevel, const Array::Ptr& val);
 	static void EmitArrayItems(std::ostream& fp, int indentLevel, const Array::Ptr& val);
-	static void EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val, const Array::Ptr& imports = Array::Ptr());
+	static void EmitScope(std::ostream& fp, int indentLevel, const Dictionary::Ptr& val,
+	    const Array::Ptr& imports = Array::Ptr(), bool splitDot = false);
 	static void EmitValue(std::ostream& fp, int indentLevel, const Value& val);
 	static void EmitRaw(std::ostream& fp, const String& val);
 	static void EmitIndent(std::ostream& fp, int indentLevel);



More information about the icinga-checkins mailing list