From 17fc1a297cf4a988d3057c262106c95135c8d997 Mon Sep 17 00:00:00 2001 From: raleng Date: Thu, 28 Jul 2022 01:36:02 +0200 Subject: [PATCH] Fix Str.split when string equals delimiter countSegments and strSplitHelp check whether the length of the string is strictly greater-than the length of the delimiter, skipping most of the logic when this is not the case. Changing the check to a greater-than-or-equal allows for the case when the string and the delimiter are equal, giving the expected result of ["", ""]. --- crates/compiler/builtins/bitcode/src/str.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/compiler/builtins/bitcode/src/str.zig b/crates/compiler/builtins/bitcode/src/str.zig index f0722213e9..24aa3ff07d 100644 --- a/crates/compiler/builtins/bitcode/src/str.zig +++ b/crates/compiler/builtins/bitcode/src/str.zig @@ -789,7 +789,7 @@ fn strSplitHelp(array: [*]RocStr, string: RocStr, delimiter: RocStr) void { const delimiter_bytes_ptrs = delimiter.asU8ptr(); const delimiter_len = delimiter.len(); - if (str_len > delimiter_len and delimiter_len > 0) { + if (str_len >= delimiter_len and delimiter_len > 0) { const end_index: usize = str_len - delimiter_len + 1; while (str_index <= end_index) { var delimiter_index: usize = 0; @@ -1104,7 +1104,7 @@ pub fn countSegments(string: RocStr, delimiter: RocStr) callconv(.C) usize { var count: usize = 1; - if (str_len > delimiter_len and delimiter_len > 0) { + if (str_len >= delimiter_len and delimiter_len > 0) { var str_index: usize = 0; const end_cond: usize = str_len - delimiter_len + 1;