Fix region highlighters validation that the delegate type exists

This commit is contained in:
Maxime Coste 2018-07-01 19:53:14 +10:00
parent 43223fba8c
commit 6993b0f347

View File

@ -1873,7 +1873,13 @@ public:
const RegexCompileFlags flags = match_capture ?
RegexCompileFlags::Optimize : RegexCompileFlags::NoSubs | RegexCompileFlags::Optimize;
auto delegate = HighlighterRegistry::instance()[parser[3]].factory(parser.positionals_from(4), nullptr);
const auto& type = parser[3];
auto& registry = HighlighterRegistry::instance();
auto it = registry.find(type);
if (it == registry.end())
throw runtime_error(format("no such highlighter type: '{}'", type));
auto delegate = it->value.factory(parser.positionals_from(4), nullptr);
return std::make_unique<RegionHighlighter>(std::move(delegate), Regex{parser[0], flags}, Regex{parser[1], flags}, parser[2].empty() ? Regex{} : Regex{parser[2], flags}, match_capture);
}