From b27d4afa8d076bc4394b3160f716bf58f586ec11 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 20 Mar 2018 04:57:47 +1100 Subject: [PATCH] Regex: Only allow SyntaxCharacter and - to be escaped in a character class Letting any character to be escaped is error prone as it looks like \l could mean [:lower:] (as it used to with boost) when it only means literal l. Fix the haskell.kak file as well. Fixes #1945 --- rc/base/haskell.kak | 2 +- src/regex_impl.cc | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/rc/base/haskell.kak b/rc/base/haskell.kak index cf06fade..25c62861 100644 --- a/rc/base/haskell.kak +++ b/rc/base/haskell.kak @@ -39,7 +39,7 @@ add-highlighter shared/haskell/code regex (?ctype; ++m_pos; continue; } - else // its just an escaped character + else // its an escaped character { cp = *m_pos++; - for (auto& control : control_escapes) - { - if (control.name == cp) - { - cp = control.value; - break; - } - } + auto it = find_if(control_escapes, [cp](auto&& t) { return t.name == cp; }); + if (it != std::end(control_escapes)) + cp = it->value; + else if (not contains("^$\\.*+?()[]{}|-", cp)) // SyntaxCharacter and - + parse_error(format("unknown character class escape '{}'", cp)); } }