diff -r a823b1aaf1f6 -r bda9d3c83cb7 src/BasicEscapingProcessor.h --- a/src/BasicEscapingProcessor.h Sat Dec 12 23:09:50 2020 +0100 +++ b/src/BasicEscapingProcessor.h Sun Dec 13 16:47:25 2020 +0100 @@ -34,14 +34,20 @@ relpipe::common::type::StringX escape(const relpipe::common::type::StringX& s, const TextType textType, const QuotingType quotingType) override { std::wstringstream result; + bool isKey = textType == TextType::EntryKey || textType == TextType::EntrySubKey; + bool isSection = textType == TextType::SectionName || textType == TextType::SectionTag; + bool isComment = textType == TextType::EntryComment || textType == TextType::SectionComment || textType == TextType::StandaloneComment; + for (auto ch : s) { if (ch == L'\\') result.put(ESC).put(ESC); else if (ch == L'\n') result.put(ESC).put(L'n'); else if (ch == L'\r'); - else if (ch == L'\t') result.put(ESC).put(L't'); + else if (isComment) result.put(ch); else if (ch == L'"' && quotingType != QuotingType::Apostrophes) result.put(ESC).put(ch); else if (ch == L'\'' && quotingType != QuotingType::Quotes) result.put(ESC).put(ch); - else if (ch == L'=' && quotingType == QuotingType::None) result.put(ESC).put(ch); + else if (ch == L'=' && quotingType == QuotingType::None && isKey) result.put(ESC).put(ch); + else if (ch == L'[' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch); + else if (ch == L']' && quotingType == QuotingType::None && (isKey || isSection)) result.put(ESC).put(ch); else result.put(ch); }