Skip to content

Commit 8126030

Browse files
authored
Merge pull request livecode#7254 from runrevmark/bugfix-22536
[[ Bug 22536 ]] Don't fail MCStringFindAndReplace if replacement not possible
2 parents 85d1f94 + 1f85320 commit 8126030

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

docs/notes/bugfix-22536.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# The replace command will no longer fail incorrectly in some cases where there are no possible replacements to be made
2+

libfoundation/src/foundation-string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5792,7 +5792,7 @@ bool MCStringFindAndReplace(MCStringRef self, MCStringRef p_pattern, MCStringRef
57925792
return MCStringFindAndReplaceNative(self, p_pattern, p_replacement, p_options);
57935793
}
57945794
else if (MCStringCantBeEqualToNative(p_pattern, p_options))
5795-
return false;
5795+
return true;
57965796
}
57975797

57985798
if (!__MCStringUnnativize(self))

tests/lcs/core/strings/replace.livecodescript

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,18 @@ on TestReplace
4242
replace tNeedle with tNewNeedle in tHaystack
4343
TestAssert "replace decomposed with base in decomposed", tHaystack is "hello"
4444
end TestReplace
45+
46+
on TestReplace_Bug22536
47+
try
48+
local tPattern
49+
put "и" into tPattern
50+
put tPattern after tPattern
51+
get the number of chars in tPattern
52+
get textDecode("foobardsdadadasdasd", "native")
53+
if true then
54+
replace tPattern with empty in it
55+
end if
56+
catch tError
57+
end try
58+
TestAssert "replace never-native unciode in native string", tError is empty
59+
end TestReplace_Bug22536

0 commit comments

Comments
 (0)