From 681ff3cc0d5f99031e9e56c091b4e8d3aabd0943 Mon Sep 17 00:00:00 2001 From: penguindark <57967770+penguindark@users.noreply.github.com> Date: Sun, 3 Jan 2021 01:33:34 +0100 Subject: [PATCH] regex: bug fix on .* cases (#7823) --- vlib/regex/regex.v | 9 ++++++++- vlib/regex/regex_test.v | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/vlib/regex/regex.v b/vlib/regex/regex.v index 1bd81b3bc2..bd403dc660 100644 --- a/vlib/regex/regex.v +++ b/vlib/regex/regex.v @@ -2000,7 +2000,7 @@ pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) { // check if we must continue or pass to the next IST if next_check_flag == true && re.prog[state.pc+1].ist != ist_prog_end { //println("save the state!!") - re.state_list << StateObj { + mut dot_state := StateObj { group_index: state.group_index match_flag: state.match_flag match_index: state.match_index @@ -2010,6 +2010,13 @@ pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) { char_len: char_len last_dot_pc: state.pc } + // if we are mananging a .* stay on the same char on return + if re.prog[state.pc].rep_min == 0 { + dot_state.i -= char_len + } + + re.state_list << dot_state + m_state = .ist_quant_n //println("dot_char stack len: ${re.state_list.len}") continue diff --git a/vlib/regex/regex_test.v b/vlib/regex/regex_test.v index 36dd9d3bd1..1ed54769cc 100644 --- a/vlib/regex/regex_test.v +++ b/vlib/regex/regex_test.v @@ -124,6 +124,7 @@ match_test_suite = [ TestItem{"accccb deer", r"^(.*)$",0,11}, TestItem{"accccb deer", r"^a(.*)b d(.+)p",-1,0}, TestItem{"##.#....#.##.####...#.##", r".{18}[.#]",0,19}, + TestItem{"#.#......##.#..#..##........##....###...##...######.......#.....#..#......#...#........###.#..#.", r'.*#[.#]{4}##[.#]{4}##[.#]{4}###',0,49}, // test bcksls chars TestItem{"[ an s. s! ]( wi4ki:something )", r"\[.*\]\( *(\w*:*\w+) *\)",0,31},