]> granicus.if.org Git - icinga2/commitdiff
Do not escape backslashes and separators twice
authorRune Darrud <theflyingcorpse@gmail.com>
Tue, 16 Aug 2016 20:16:37 +0000 (22:16 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 17 Aug 2016 04:10:41 +0000 (06:10 +0200)
fixes #12227

Signed-off-by: Gunnar Beutner <gunnar.beutner@netways.de>
lib/base/utility.cpp
lib/base/utility.hpp
lib/perfdata/influxdbwriter.cpp

index 9834a643e0745797a131af7975b2952a0ff0a33e..82470822fd6b60e8951963a01372f9ea766a5f24 100644 (file)
@@ -939,7 +939,7 @@ String Utility::NaturalJoin(const std::vector<String>& tokens)
        return result;
 }
 
-String Utility::Join(const Array::Ptr& tokens, char separator)
+String Utility::Join(const Array::Ptr& tokens, char separator, bool escapeSeparator)
 {
        String result;
        bool first = true;
@@ -947,15 +947,18 @@ String Utility::Join(const Array::Ptr& tokens, char separator)
        ObjectLock olock(tokens);
        BOOST_FOREACH(const Value& vtoken, tokens) {
                String token = Convert::ToString(vtoken);
-               boost::algorithm::replace_all(token, "\\", "\\\\");
-
-               char sep_before[2], sep_after[3];
-               sep_before[0] = separator;
-               sep_before[1] = '\0';
-               sep_after[0] = '\\';
-               sep_after[1] = separator;
-               sep_after[2] = '\0';
-               boost::algorithm::replace_all(token, sep_before, sep_after);
+
+               if (escapeSeparator) {
+                       boost::algorithm::replace_all(token, "\\", "\\\\");
+
+                       char sep_before[2], sep_after[3];
+                       sep_before[0] = separator;
+                       sep_before[1] = '\0';
+                       sep_after[0] = '\\';
+                       sep_after[1] = separator;
+                       sep_after[2] = '\0';
+                       boost::algorithm::replace_all(token, sep_before, sep_after);
+               }
 
                if (first)
                        first = false;
index ea5bf3f129c931e01a479bd05c0ba14231421fc2..0e1fcc29ff3233647e8f4cd1de10e9429f4462e1 100644 (file)
@@ -89,7 +89,7 @@ public:
        static void QueueAsyncCallback(const boost::function<void (void)>& callback, SchedulerPolicy policy = DefaultScheduler);
 
        static String NaturalJoin(const std::vector<String>& tokens);
-       static String Join(const Array::Ptr& tokens, char separator);
+       static String Join(const Array::Ptr& tokens, char separator, bool escapeSeparator = true);
 
        static String FormatDuration(double duration);
        static String FormatDateTime(const char *format, double ts);
index 6eb8d0091fed66e7427a8a82a950d3498a5fdb68..239db8995fd9a98f37b177f2db7d48e57c3d872e 100644 (file)
@@ -235,6 +235,8 @@ String InfluxdbWriter::EscapeKey(const String& str)
 {
        // Iterate over the key name and escape commas and spaces with a backslash
        String result = str;
+       boost::algorithm::replace_all(result, "\"", "\\\"");
+       boost::algorithm::replace_all(result, "=", "\\=");
        boost::algorithm::replace_all(result, ",", "\\,");
        boost::algorithm::replace_all(result, " ", "\\ ");
 
@@ -366,7 +368,7 @@ void InfluxdbWriter::Flush(void)
 
        // Ensure you hold a lock against m_DataBuffer so that things
        // don't go missing after creating the body and clearing the buffer
-       String body = Utility::Join(m_DataBuffer, '\n');
+       String body = Utility::Join(m_DataBuffer, '\n', false);
        m_DataBuffer->Clear();
 
        HttpRequest req(stream);