regex: fix '\0' terminator always matched as last character(fix #19802) (#20104)

This commit is contained in:
shove 2023-12-07 00:07:42 +08:00 committed by GitHub
parent 55e86febf6
commit 772f11494f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -2429,7 +2429,8 @@ pub fn (mut re RE) match_base(in_txt &u8, in_txt_len int) (int, int) {
// println("ist_simple_char")
state.match_flag = false
if re.prog[state.pc].ch == ch {
if re.prog[state.pc].ch == ch
&& (state.i < in_txt_len - 1 || re.prog[state.pc].ch != 0) {
state.match_flag = true
l_ist = regex.ist_simple_char

View File

@ -185,6 +185,14 @@ match_test_suite = [
// test last charr classes neg class
TestItem{"/a/", r"^/a/[^/]+$", -1,3},
TestItem{"/a/b",r"^/a/[^/]+$", 0,4},
// test `\0` as terminator
TestItem{"abc", "^abc\0$", -1,3},
TestItem{"abc\0", "^abc\0$", 0,4},
// test has `\0` chars
TestItem{"abcxyz", "^abc\0xyz$", -1,3},
TestItem{"abc\0xyz", "^abc\0xyz$", 0,7},
]
)