Do not escape backslashes and separators twice

fixes #12227

Signed-off-by: Gunnar Beutner <gunnar.beutner@netways.de>
This commit is contained in:
Rune Darrud 2016-08-16 22:16:37 +02:00 committed by Gunnar Beutner
parent 162e31b083
commit 5c0b3c58bd
3 changed files with 16 additions and 11 deletions

View File

@ -939,7 +939,7 @@ String Utility::NaturalJoin(const std::vector<String>& tokens)
return result; return result;
} }
String Utility::Join(const Array::Ptr& tokens, char separator) String Utility::Join(const Array::Ptr& tokens, char separator, bool escapeSeparator)
{ {
String result; String result;
bool first = true; bool first = true;
@ -947,15 +947,18 @@ String Utility::Join(const Array::Ptr& tokens, char separator)
ObjectLock olock(tokens); ObjectLock olock(tokens);
BOOST_FOREACH(const Value& vtoken, tokens) { BOOST_FOREACH(const Value& vtoken, tokens) {
String token = Convert::ToString(vtoken); String token = Convert::ToString(vtoken);
boost::algorithm::replace_all(token, "\\", "\\\\");
char sep_before[2], sep_after[3]; if (escapeSeparator) {
sep_before[0] = separator; boost::algorithm::replace_all(token, "\\", "\\\\");
sep_before[1] = '\0';
sep_after[0] = '\\'; char sep_before[2], sep_after[3];
sep_after[1] = separator; sep_before[0] = separator;
sep_after[2] = '\0'; sep_before[1] = '\0';
boost::algorithm::replace_all(token, sep_before, sep_after); sep_after[0] = '\\';
sep_after[1] = separator;
sep_after[2] = '\0';
boost::algorithm::replace_all(token, sep_before, sep_after);
}
if (first) if (first)
first = false; first = false;

View File

@ -89,7 +89,7 @@ public:
static void QueueAsyncCallback(const boost::function<void (void)>& callback, SchedulerPolicy policy = DefaultScheduler); static void QueueAsyncCallback(const boost::function<void (void)>& callback, SchedulerPolicy policy = DefaultScheduler);
static String NaturalJoin(const std::vector<String>& tokens); 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 FormatDuration(double duration);
static String FormatDateTime(const char *format, double ts); static String FormatDateTime(const char *format, double ts);

View File

@ -235,6 +235,8 @@ String InfluxdbWriter::EscapeKey(const String& str)
{ {
// Iterate over the key name and escape commas and spaces with a backslash // Iterate over the key name and escape commas and spaces with a backslash
String result = str; String result = str;
boost::algorithm::replace_all(result, "\"", "\\\"");
boost::algorithm::replace_all(result, "=", "\\=");
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 // Ensure you hold a lock against m_DataBuffer so that things
// don't go missing after creating the body and clearing the buffer // 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(); m_DataBuffer->Clear();
HttpRequest req(stream); HttpRequest req(stream);