From 6993b0f347733aa24354af520789c1cefd5ff576 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 1 Jul 2018 19:53:14 +1000 Subject: [PATCH] Fix region highlighters validation that the delegate type exists --- src/highlighters.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index ddd0d6c6a..11c4558b0 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -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(std::move(delegate), Regex{parser[0], flags}, Regex{parser[1], flags}, parser[2].empty() ? Regex{} : Regex{parser[2], flags}, match_capture); }