From 438bdd1b0b807bdf6b3d4bfad6d67a39e5225f7f Mon Sep 17 00:00:00 2001 From: penguindark <57967770+penguindark@users.noreply.github.com> Date: Mon, 6 Sep 2021 02:11:38 +0200 Subject: [PATCH] regex: fix #11404 (#11406) --- vlib/regex/regex.v | 13 +++++++++++++ vlib/regex/regex_test.v | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 68ea823f5d..46dccb049c 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -1768,6 +1768,17 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { // m_state = .end // break + + // no groups open, check the last token quantifier + if ist != regex.ist_group_end && re.prog[state.pc + 1].ist == regex.ist_prog_end { + if re.prog[state.pc].rep >= re.prog[state.pc].rep_min + && re.prog[state.pc].rep <= re.prog[state.pc].rep_max { + // println("We are in good repetition") + return state.first_match, state.i + } + } + + // print("No good exit!!") return regex.no_match_found, 0 } @@ -2268,12 +2279,14 @@ pub fn (mut re RE) match_base(in_txt &byte, in_txt_len int) (int, int) { } // ist_quant_p => quantifier positive test on token else if m_state == .ist_quant_p { + // println("Here .ist_quant_p") // exit on first match if (re.flag & regex.f_efm) != 0 { return state.i, state.i + 1 } rep := re.prog[state.pc].rep + // println(rep) // under range if rep > 0 && rep < re.prog[state.pc].rep_min { diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index 1239b250e4..8fc9fa7096 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -155,6 +155,10 @@ match_test_suite = [ // particular groups TestItem{"ababababac", r"ab(.*)(ac)",0,10}, + // backslash on finish string + TestItem{"a", r"\S+",0,1}, + TestItem{"aaaa", r"\S+",0,4}, + TestItem{"aaaa ", r"\S+",0,4}, ] )