[core:text/regex] Fix #6323 and add test case

Thanks to @GPotoshin for the fix.
This commit is contained in:
Jeroen van Rijn
2026-02-25 10:49:27 +01:00
parent 545d17fd8d
commit e696073d7b
2 changed files with 23 additions and 9 deletions

View File

@@ -203,18 +203,22 @@ add_thread :: proc(vm: ^Machine, saved: ^[2 * common.MAX_CAPTURE_GROUPS]int, pc:
}
case .Assert_Word_Boundary:
sp := vm.string_pointer+vm.current_rune_size
if sp == 0 || sp == len(vm.memory) {
left_is_wc := false
if sp > 0 {
left_is_wc = is_word_class(vm.current_rune)
}
right_is_wc := false
if sp < len(vm.memory) {
right_is_wc = is_word_class(vm.next_rune)
}
if left_is_wc != right_is_wc {
pc += size_of(Opcode)
continue
} else {
last_rune_is_wc := is_word_class(vm.current_rune)
this_rune_is_wc := is_word_class(vm.next_rune)
if last_rune_is_wc && !this_rune_is_wc || !last_rune_is_wc && this_rune_is_wc {
pc += size_of(Opcode)
continue
}
}
case .Assert_Non_Word_Boundary:
sp := vm.string_pointer+vm.current_rune_size
if sp != 0 && sp != len(vm.memory) {

View File

@@ -1270,6 +1270,16 @@ iterator_vectors := []Iterator_Test{
{pos = {{0, 2}}, groups = {"a\n"}},
},
},
// https://github.com/odin-lang/Odin/issues/6323
// Test `\b` in iterator
{
"can, can't, 'can't'", `\b[a-z0-9']+\b`, {},
{
{pos = {{0, 3}}, groups = {"can"}},
{pos = {{5, 10}}, groups = {"can't"}},
{pos = {{13, 18}}, groups = {"can't"}},
},
}
}
@test