summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2016-12-17 05:48:42 +0000
committerMaxime Coste <mawww@kakoune.org>2016-12-17 05:48:42 +0000
commit2bdd361948c1dee3f9b74ee6d439fdd9dba1b32e (patch)
tree89124c2b785bb83ef871370d8ca84f83a2f18745
parentdc84cdd5384523ccf6ff00bb227d174965ed9289 (diff)
Escape the backslash chars as well when joining strings
Fixes #1014
-rw-r--r--src/string.hh3
-rw-r--r--test/regression/1014-ambiguous-kak_selections/cmd1
-rw-r--r--test/regression/1014-ambiguous-kak_selections/in3
-rw-r--r--test/regression/1014-ambiguous-kak_selections/selections1
4 files changed, 7 insertions, 1 deletions
diff --git a/src/string.hh b/src/string.hh
index 6fd2f5fb..00a20adc 100644
--- a/src/string.hh
+++ b/src/string.hh
@@ -330,12 +330,13 @@ String replace(StringView str, StringView substr, StringView replacement);
template<typename Container>
String join(const Container& container, char joiner, bool esc_joiner = true)
{
+ const char to_escape[] = { joiner, '\\' };
String res;
for (const auto& str : container)
{
if (not res.empty())
res += joiner;
- res += esc_joiner ? escape(str, joiner, '\\') : str;
+ res += esc_joiner ? escape(str, to_escape, '\\') : str;
}
return res;
}
diff --git a/test/regression/1014-ambiguous-kak_selections/cmd b/test/regression/1014-ambiguous-kak_selections/cmd
new file mode 100644
index 00000000..2783a13e
--- /dev/null
+++ b/test/regression/1014-ambiguous-kak_selections/cmd
@@ -0,0 +1 @@
+%<a-s>H
diff --git a/test/regression/1014-ambiguous-kak_selections/in b/test/regression/1014-ambiguous-kak_selections/in
new file mode 100644
index 00000000..819467ab
--- /dev/null
+++ b/test/regression/1014-ambiguous-kak_selections/in
@@ -0,0 +1,3 @@
+foo\:bar
+foo\\
+bar
diff --git a/test/regression/1014-ambiguous-kak_selections/selections b/test/regression/1014-ambiguous-kak_selections/selections
new file mode 100644
index 00000000..16016faf
--- /dev/null
+++ b/test/regression/1014-ambiguous-kak_selections/selections
@@ -0,0 +1 @@
+foo\\\:bar:foo\\\\:bar