Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 13e71f5

Browse files
Port dotnet/runtime#31946 to release/uwp6.2 branch (#28015)
When string.Replace is given a target string with zero collation weight, it would enter an infinite loop. It is now changed so that the call to Replace terminates when such a condition is encountered.
1 parent b33c7d0 commit 13e71f5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/mscorlib/shared/System/String.Manipulation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,11 @@ private unsafe string ReplaceCore(string oldValue, string newValue, CultureInfo
967967
do
968968
{
969969
index = ci.IndexOf(this, oldValue, startIndex, this.Length - startIndex, options, &matchLength);
970-
if (index >= 0)
970+
971+
// There's the possibility that 'oldValue' has zero collation weight (empty string equivalent).
972+
// If this is the case, we behave as if there are no more substitutions to be made.
973+
974+
if (index >= 0 && matchLength > 0)
971975
{
972976
// append the unmodified portion of string
973977
result.Append(this, startIndex, index - startIndex);

0 commit comments

Comments
 (0)