Skip to content

Commit 1f85320

Browse files
committed
[[ Bug 22536 ]] Don't fail MCStringFindAndReplace if replacement not possible
This patch ensures that MCStringFindAndReplace won't fail if it determines that the target string is native and the pattern string cannot ever be native (and thus not exist in the target). The case this optimization occurs is not hugely common as it requires the pattern string to have been 'checked' at some point. The method will now just exit early in this case.
1 parent 3435327 commit 1f85320

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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
@@ -5748,7 +5748,7 @@ bool MCStringFindAndReplace(MCStringRef self, MCStringRef p_pattern, MCStringRef
57485748
return MCStringFindAndReplaceNative(self, p_pattern, p_replacement, p_options);
57495749
}
57505750
else if (MCStringCantBeEqualToNative(p_pattern, p_options))
5751-
return false;
5751+
return true;
57525752
}
57535753

57545754
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)