summaryrefslogtreecommitdiff
path: root/src/command_manager.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2016-12-07 20:07:32 +0000
committerMaxime Coste <mawww@kakoune.org>2016-12-07 20:07:32 +0000
commit03eb128536acb3d870b7010ae3cad3d2b707cf72 (patch)
tree536eb80b5906fb7cee33d119592b99c0857277c3 /src/command_manager.cc
parentbc8b30c988cf8b471cac0b2bc5cea9fd8594c846 (diff)
Ensure content of expanded strings in modelinefmt is not interpreted as markup
Diffstat (limited to 'src/command_manager.cc')
-rw-r--r--src/command_manager.cc25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 0738915c..d5307032 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -348,8 +348,10 @@ TokenList parse(StringView line)
return result;
}
-String expand(StringView str, const Context& context,
- const ShellContext& shell_context)
+template<typename Postprocess>
+String expand_impl(StringView str, const Context& context,
+ const ShellContext& shell_context,
+ Postprocess postprocess)
{
Reader reader{str};
String res;
@@ -370,8 +372,8 @@ String expand(StringView str, const Context& context,
else if (c == '%')
{
res += reader.substr_from(beg);
- Token token = parse_percent_token<true>(reader);
- res += expand_token(token, context, shell_context);
+ res += postprocess(expand_token(parse_percent_token<true>(reader),
+ context, shell_context));
beg = (++reader).pos;
}
else
@@ -381,6 +383,21 @@ String expand(StringView str, const Context& context,
return res;
}
+String expand(StringView str, const Context& context,
+ const ShellContext& shell_context)
+{
+ return expand_impl(str, context, shell_context,
+ [](String s) { return std::move(s); });
+}
+
+String expand(StringView str, const Context& context,
+ const ShellContext& shell_context,
+ std::function<String (String)> postprocess)
+{
+ return expand_impl(str, context, shell_context,
+ [&](String s) { return postprocess(std::move(s)); });
+}
+
struct command_not_found : runtime_error
{
command_not_found(StringView command)