Escape the backslash chars as well when joining strings

Fixes #1014
This commit is contained in:
Maxime Coste 2016-12-17 05:48:42 +00:00
parent dc84cdd538
commit 2bdd361948
4 changed files with 7 additions and 1 deletions

View File

@ -330,12 +330,13 @@ String replace(StringView str, StringView substr, StringView replacement);
template<typename Container> template<typename Container>
String join(const Container& container, char joiner, bool esc_joiner = true) String join(const Container& container, char joiner, bool esc_joiner = true)
{ {
const char to_escape[] = { joiner, '\\' };
String res; String res;
for (const auto& str : container) for (const auto& str : container)
{ {
if (not res.empty()) if (not res.empty())
res += joiner; res += joiner;
res += esc_joiner ? escape(str, joiner, '\\') : str; res += esc_joiner ? escape(str, to_escape, '\\') : str;
} }
return res; return res;
} }

View File

@ -0,0 +1 @@
%<a-s>H

View File

@ -0,0 +1,3 @@
foo\:bar
foo\\
bar

View File

@ -0,0 +1 @@
foo\\\:bar:foo\\\\:bar