diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-03-20 04:57:47 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-03-20 04:57:47 +1100 |
| commit | b27d4afa8d076bc4394b3160f716bf58f586ec11 (patch) | |
| tree | bf1e6c5178cf84dcf466cd69d0f2d1e0f4158f27 /src | |
| parent | 6fdb9db5d90d7504b21158c146a59af66565ff63 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex_impl.cc | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 7870fb56..1c2dfd84 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -429,24 +429,21 @@ private: if (cp == '\\') { auto it = find_if(character_class_escapes, - [cp = *m_pos](auto& t) { return t.cp == cp; }); + [cp = *m_pos](auto&& t) { return t.cp == cp; }); if (it != std::end(character_class_escapes)) { character_class.ctypes |= it->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)); } } |
