summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLevi Broderick <GrabYourPitchforks@users.noreply.github.com>2020-02-18 21:32:57 (GMT)
committerGitHub <noreply@github.com>2020-02-18 21:32:57 (GMT)
commitb4b4098794a58914e4a1d2897c59d1fe995d1a0d (patch)
tree2f361f49511f11601c7f3bea41f6ff87f9efa8f4 /src
parenta95569a88d35ea4d3ec9e0ecbe6f1acb5e72a063 (diff)
downloadcoreclr-b4b4098794a58914e4a1d2897c59d1fe995d1a0d.zip
coreclr-b4b4098794a58914e4a1d2897c59d1fe995d1a0d.tar.gz
coreclr-b4b4098794a58914e4a1d2897c59d1fe995d1a0d.tar.bz2
Port dotnet/runtime#31946 to release/3.1 branch (#28014)
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.
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/String.Manipulation.cs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs
index 564fca0..daf6fc3 100644
--- a/src/System.Private.CoreLib/shared/System/String.Manipulation.cs
+++ b/src/System.Private.CoreLib/shared/System/String.Manipulation.cs
@@ -1020,7 +1020,11 @@ namespace System
do
{
index = ci.IndexOf(this, oldValue, startIndex, this.Length - startIndex, options, &matchLength);
- if (index >= 0)
+
+ // There's the possibility that 'oldValue' has zero collation weight (empty string equivalent).
+ // If this is the case, we behave as if there are no more substitutions to be made.
+
+ if (index >= 0 && matchLength > 0)
{
// append the unmodified portion of string
result.Append(this, startIndex, index - startIndex);