diff options
author | Levi Broderick <GrabYourPitchforks@users.noreply.github.com> | 2020-02-18 13:32:57 -0800 |
---|---|---|
committer | Hyungju Lee <leee.lee@samsung.com> | 2020-10-30 18:20:12 +0900 |
commit | 5731dae07d086f8ed4408fb95de764cbc659d4ac (patch) | |
tree | ffbf945b25cc0b70ebdfe2a5821db333b9d5c15e | |
parent | 6b424c4ff0ae01913d75973312ca33f6436973ac (diff) | |
download | coreclr-5731dae07d086f8ed4408fb95de764cbc659d4ac.tar.gz coreclr-5731dae07d086f8ed4408fb95de764cbc659d4ac.tar.bz2 coreclr-5731dae07d086f8ed4408fb95de764cbc659d4ac.zip |
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.
-rw-r--r-- | src/System.Private.CoreLib/shared/System/String.Manipulation.cs | 6 |
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 564fca0dcd..daf6fc3dff 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); |