1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-19 17:31:44 +03:00

Ensure content of expanded strings in modelinefmt is not interpreted as markup

This commit is contained in:
Maxime Coste 2016-12-07 20:07:32 +00:00
parent bc8b30c988
commit 03eb128536
3 changed files with 27 additions and 5 deletions

View File

@ -116,7 +116,8 @@ DisplayLine Client::generate_mode_line() const
{
const String& modelinefmt = context().options()["modelinefmt"].get<String>();
modeline = parse_display_line(expand(modelinefmt, context()));
modeline = parse_display_line(expand(modelinefmt, context(), ShellContext{},
[](String s) { return escape(s, '{', '\\'); }));
}
catch (runtime_error& err)
{

View File

@ -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)

View File

@ -133,6 +133,10 @@ private:
String expand(StringView str, const Context& context,
const ShellContext& shell_context = ShellContext{});
String expand(StringView str, const Context& context,
const ShellContext& shell_context,
std::function<String (String)> postprocess);
}
#endif // command_manager_hh_INCLUDED