Ensure content of expanded strings in modelinefmt is not interpreted as markup
This commit is contained in:
parent
bc8b30c988
commit
03eb128536
|
@ -116,7 +116,8 @@ DisplayLine Client::generate_mode_line() const
|
||||||
{
|
{
|
||||||
const String& modelinefmt = context().options()["modelinefmt"].get<String>();
|
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)
|
catch (runtime_error& err)
|
||||||
{
|
{
|
||||||
|
|
|
@ -348,8 +348,10 @@ TokenList parse(StringView line)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
String expand(StringView str, const Context& context,
|
template<typename Postprocess>
|
||||||
const ShellContext& shell_context)
|
String expand_impl(StringView str, const Context& context,
|
||||||
|
const ShellContext& shell_context,
|
||||||
|
Postprocess postprocess)
|
||||||
{
|
{
|
||||||
Reader reader{str};
|
Reader reader{str};
|
||||||
String res;
|
String res;
|
||||||
|
@ -370,8 +372,8 @@ String expand(StringView str, const Context& context,
|
||||||
else if (c == '%')
|
else if (c == '%')
|
||||||
{
|
{
|
||||||
res += reader.substr_from(beg);
|
res += reader.substr_from(beg);
|
||||||
Token token = parse_percent_token<true>(reader);
|
res += postprocess(expand_token(parse_percent_token<true>(reader),
|
||||||
res += expand_token(token, context, shell_context);
|
context, shell_context));
|
||||||
beg = (++reader).pos;
|
beg = (++reader).pos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -381,6 +383,21 @@ String expand(StringView str, const Context& context,
|
||||||
return res;
|
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
|
struct command_not_found : runtime_error
|
||||||
{
|
{
|
||||||
command_not_found(StringView command)
|
command_not_found(StringView command)
|
||||||
|
|
|
@ -133,6 +133,10 @@ private:
|
||||||
String expand(StringView str, const Context& context,
|
String expand(StringView str, const Context& context,
|
||||||
const ShellContext& shell_context = ShellContext{});
|
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
|
#endif // command_manager_hh_INCLUDED
|
||||||
|
|
Loading…
Reference in New Issue
Block a user