From c282b699d7d099ee59f6335e3cbd3d3bdd33a6e3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 26 Sep 2017 23:37:21 +0900 Subject: [PATCH] Regex: fix support for `-` at end of a character class --- src/regex_impl.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/regex_impl.cc b/src/regex_impl.cc index aa527c0c..99b56528 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -270,9 +270,17 @@ private: { if (++m_pos == m_regex.end()) break; - range.max = *m_pos++; - if (range.min > range.max) - parse_error("invalid range specified"); + if (*m_pos != ']') + { + range.max = *m_pos++; + if (range.min > range.max) + parse_error("invalid range specified"); + } + else + { + ranges.push_back(range); + range = { '-', '-' }; + } } ranges.push_back(range); } @@ -934,8 +942,8 @@ auto test_regex = UnitTest{[]{ } { - TestVM vm{R"([àb-dX-Z]{3,5})"}; - kak_assert(vm.exec("càY")); + TestVM vm{R"([àb-dX-Z-]{3,5})"}; + kak_assert(vm.exec("cà-Y")); kak_assert(not vm.exec("àeY")); kak_assert(vm.exec("dcbàX")); kak_assert(not vm.exec("efg"));