Skip to content

Commit 66f7bb6

Browse files
committed
libfoundation: Fix Unicode string split with missing key delimiter
When splitting Unicode strings, make the behaviour when the key delimiter is not found consistent with the behaviour for native strings.
1 parent f966053 commit 66f7bb6

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

libfoundation/src/foundation-string.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,23 +4426,30 @@ static void split_find_end_of_element_and_key(const void *sptr, uindex_t length,
44264426
t_del_found = MCUnicodeFind(sptr, length, native, p_del, p_del_length, p_del_native, (MCUnicodeCompareOption)p_options, t_del_found_range);
44274427
// SN-2014-07-29: [[ Bug 13018 ]] Use t_key_found_range for the key, not t_del_found_range
44284428
t_key_found = MCUnicodeFind(sptr, length, native, p_key, p_key_length, p_key_native, (MCUnicodeCompareOption)p_options, t_key_found_range);
4429-
4430-
if (!t_key_found)
4431-
r_key_end = length;
4432-
4433-
if (!t_del_found)
4434-
r_element_end = length;
4435-
4436-
if (t_key_found_range . offset > t_del_found_range . offset)
4437-
{
4438-
// Delimiter came before the key
4439-
r_key_end = r_element_end = length;
4440-
return;
4441-
}
4442-
4443-
r_key_end = t_key_found_range . offset;
4444-
r_key_found_length = t_key_found_range . length;
4445-
split_find_end_of_element(sptr, length, native, p_del, p_del_length, p_del_native, p_options, r_element_end, r_del_found_length);
4429+
4430+
if (!t_del_found)
4431+
{
4432+
r_element_end = length;
4433+
r_del_found_length = 0;
4434+
}
4435+
else
4436+
{
4437+
r_element_end = t_del_found_range.offset;
4438+
r_del_found_length = t_del_found_range.length;
4439+
}
4440+
4441+
/* Deal with the possibility that the delimiter was found before the key */
4442+
if (!t_key_found ||
4443+
r_element_end < t_key_found_range.offset)
4444+
{
4445+
r_key_end = r_element_end;
4446+
r_key_found_length = 0;
4447+
}
4448+
else
4449+
{
4450+
r_key_end = t_key_found_range.offset;
4451+
r_key_found_length = t_key_found_range.length;
4452+
}
44464453
}
44474454

44484455
bool MCStringSplit(MCStringRef self, MCStringRef p_elem_del, MCStringRef p_key_del, MCStringOptions p_options, MCArrayRef& r_array)

tests/lcs/core/array/split.livecodescript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ on TestSplit
8484
put empty into tExpected[tRArrow]
8585
put empty into tExpected[tLArrow]
8686
split tResult by "," and ":"
87-
TestAssertBroken "split key missing (unicode, native, native)", tResult is tExpected
87+
TestAssert "split key missing (unicode, native, native)", tResult is tExpected
8888
end TestSplit
8989

9090

0 commit comments

Comments
 (0)