From 02d284587881ebd547fd7d81fe485075b6b1c04f Mon Sep 17 00:00:00 2001 From: John Date: Sun, 14 Feb 2021 11:33:25 +0100 Subject: [PATCH] fix escaping '"' in config format --- src/lib/ebus/data.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/ebus/data.cpp b/src/lib/ebus/data.cpp index 66b0154a1..7c69ba451 100644 --- a/src/lib/ebus/data.cpp +++ b/src/lib/ebus/data.cpp @@ -70,10 +70,22 @@ void AttributedItem::dumpString(bool prependFieldSeparator, const string& str, o if (prependFieldSeparator) { *output << FIELD_SEPARATOR; } - if (str.find_first_of(FIELD_SEPARATOR) == string::npos) { + string::size_type pos = str.find_first_of(TEXT_SEPARATOR); + if (str.find_first_of(FIELD_SEPARATOR) == string::npos + && (pos == string::npos || (pos > 0 && pos < str.length() - 1))) { *output << str; - } else { + } else if (pos == string::npos) { *output << TEXT_SEPARATOR << str << TEXT_SEPARATOR; + } else { + *output << TEXT_SEPARATOR; + string::size_type last = 0; + while (pos != string::npos) { + *output << str.substr(last, pos - last); + *output << TEXT_SEPARATOR << TEXT_SEPARATOR; + last = pos+1; + pos = str.find_first_of(TEXT_SEPARATOR, last); + } + *output << str.substr(last) << TEXT_SEPARATOR; } }