Skip to content

Commit e696073

Browse files
committed
[core:text/regex] Fix #6323 and add test case
Thanks to @GPotoshin for the fix.
1 parent 545d17f commit e696073

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

core/text/regex/virtual_machine/virtual_machine.odin

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,22 @@ add_thread :: proc(vm: ^Machine, saved: ^[2 * common.MAX_CAPTURE_GROUPS]int, pc:
203203
}
204204
case .Assert_Word_Boundary:
205205
sp := vm.string_pointer+vm.current_rune_size
206-
if sp == 0 || sp == len(vm.memory) {
206+
207+
left_is_wc := false
208+
if sp > 0 {
209+
left_is_wc = is_word_class(vm.current_rune)
210+
}
211+
212+
right_is_wc := false
213+
if sp < len(vm.memory) {
214+
right_is_wc = is_word_class(vm.next_rune)
215+
}
216+
217+
if left_is_wc != right_is_wc {
207218
pc += size_of(Opcode)
208219
continue
209-
} else {
210-
last_rune_is_wc := is_word_class(vm.current_rune)
211-
this_rune_is_wc := is_word_class(vm.next_rune)
212-
213-
if last_rune_is_wc && !this_rune_is_wc || !last_rune_is_wc && this_rune_is_wc {
214-
pc += size_of(Opcode)
215-
continue
216-
}
217220
}
221+
218222
case .Assert_Non_Word_Boundary:
219223
sp := vm.string_pointer+vm.current_rune_size
220224
if sp != 0 && sp != len(vm.memory) {

tests/core/text/regex/test_core_text_regex.odin

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,16 @@ iterator_vectors := []Iterator_Test{
12701270
{pos = {{0, 2}}, groups = {"a\n"}},
12711271
},
12721272
},
1273+
// https://github.com/odin-lang/Odin/issues/6323
1274+
// Test `\b` in iterator
1275+
{
1276+
"can, can't, 'can't'", `\b[a-z0-9']+\b`, {},
1277+
{
1278+
{pos = {{0, 3}}, groups = {"can"}},
1279+
{pos = {{5, 10}}, groups = {"can't"}},
1280+
{pos = {{13, 18}}, groups = {"can't"}},
1281+
},
1282+
}
12731283
}
12741284

12751285
@test

0 commit comments

Comments
 (0)