mirror of https://github.com/Icinga/icinga2.git
Fix: Escaped sequences not properly generated with 'node update-config'
fixes #10989
This commit is contained in:
parent
fd85379f5c
commit
abce99daff
|
@ -680,7 +680,7 @@ void RepositoryUtility::FormatChangelogEntry(std::ostream& fp, const Dictionary:
|
|||
*/
|
||||
void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object)
|
||||
{
|
||||
fp << "object " << type << " \"" << name << "\" {\n";
|
||||
fp << "object " << type << " \"" << EscapeIcingaString(name) << "\" {\n";
|
||||
|
||||
if (!object) {
|
||||
fp << "}\n";
|
||||
|
@ -709,6 +709,19 @@ void RepositoryUtility::SerializeObject(std::ostream& fp, const String& name, co
|
|||
fp << "}\n";
|
||||
}
|
||||
|
||||
String RepositoryUtility::EscapeIcingaString(const String& str)
|
||||
{
|
||||
String result = str;
|
||||
boost::algorithm::replace_all(result, "\\", "\\\\");
|
||||
boost::algorithm::replace_all(result, "\n", "\\n");
|
||||
boost::algorithm::replace_all(result, "\t", "\\t");
|
||||
boost::algorithm::replace_all(result, "\r", "\\r");
|
||||
boost::algorithm::replace_all(result, "\b", "\\b");
|
||||
boost::algorithm::replace_all(result, "\f", "\\f");
|
||||
boost::algorithm::replace_all(result, "\"", "\\\"");
|
||||
return result;
|
||||
}
|
||||
|
||||
void RepositoryUtility::FormatValue(std::ostream& fp, const Value& val)
|
||||
{
|
||||
if (val.IsObjectType<Array>()) {
|
||||
|
@ -717,11 +730,11 @@ void RepositoryUtility::FormatValue(std::ostream& fp, const Value& val)
|
|||
}
|
||||
|
||||
if (val.IsString()) {
|
||||
fp << "\"" << Convert::ToString(val) << "\"";
|
||||
fp << "\"" << EscapeIcingaString(val) << "\"";
|
||||
return;
|
||||
}
|
||||
|
||||
fp << Convert::ToString(val);
|
||||
fp << EscapeIcingaString(val);
|
||||
}
|
||||
|
||||
void RepositoryUtility::FormatArray(std::ostream& fp, const Array::Ptr& arr)
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
|
||||
/* config print helpers */
|
||||
static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
|
||||
static String EscapeIcingaString(const String& str);
|
||||
static void FormatValue(std::ostream& fp, const Value& val);
|
||||
static void FormatArray(std::ostream& fp, const Array::Ptr& arr);
|
||||
|
||||
|
|
Loading…
Reference in New Issue