U4-2635 Skip past replaced word when checking

Avoids infinite loop if search and replacement are equal
This commit is contained in:
John
2014-04-29 13:54:26 +02:00
parent 74dd1f9181
commit b4127294e5
2 changed files with 9 additions and 4 deletions

View File

@@ -83,6 +83,9 @@ namespace Umbraco.Tests.CoreStrings
[TestCase("Hello this is my string", "hello", "replaced", "replaced this is my string", StringComparison.CurrentCultureIgnoreCase)]
[TestCase("Hello this is hello my string", "hello", "replaced", "replaced this is replaced my string", StringComparison.CurrentCultureIgnoreCase)]
[TestCase("Hello this is my string", "nonexistent", "replaced", "Hello this is my string", StringComparison.CurrentCultureIgnoreCase)]
[TestCase("Hellohello this is my string", "hello", "replaced", "replacedreplaced this is my string", StringComparison.CurrentCultureIgnoreCase)]
// Ensure replacing with the same string doesn't cause infinite loop.
[TestCase("Hello this is my string", "hello", "hello", "hello this is my string", StringComparison.CurrentCultureIgnoreCase)]
public void ReplaceWithStringComparison(string input, string oldString, string newString, string shouldBe, StringComparison stringComparison)
{
var replaced = input.Replace(oldString, newString, stringComparison);