Hello,
There is a bug in ReplaceAll method in ServiceStack.Text StringExtensions.cs
Current:
public static string ReplaceAll(this string haystack, string needle, string replacement)
{
int pos;
// Avoid a possible infinite loop
if (needle == replacement) return haystack;
while ((pos = haystack.IndexOf(needle, StringComparison.Ordinal)) > 0)
{
haystack = haystack.Substring(0, pos)
+ replacement
+ haystack.Substring(pos + needle.Length);
}
return haystack;
}
while condition should be " >= 0 ".
Currently it fails on replacing single character when it is in first place.
Example:
var result = "/images".ReplaceAll("/", string.Empty); <- Result: "/images", Expected "images"
Kind regards