Special-case value.Length == 0 in LastIndexOfOrdinal
authorStephen Toub <stoub@microsoft.com>
Wed, 1 Apr 2015 03:20:44 +0000 (23:20 -0400)
committerStephen Toub <stoub@microsoft.com>
Wed, 1 Apr 2015 03:20:44 +0000 (23:20 -0400)
With https://github.com/dotnet/coreclr/pull/579, I added to IndexOfOrdinal a check for value.Length == 0, to avoid returning bad data in that case.  But in doing so, and in neglecting to add a similar check to LastIndexOfOrdinal (which is currently implemented in terms of IndexOfOrdinal), I introduced an infinite loop into LastIndexOfOrdinal when value.Length == 0.  Fixing by adding a similar special-case.

src/mscorlib/corefx/System/Globalization/CompareInfo.Unix.cs

index 137b798..8091eeb 100644 (file)
@@ -54,6 +54,12 @@ namespace System.Globalization
             Contract.Assert(value != null);
 
             // TODO: Implement This Fully.
+
+            if (value.Length == 0)
+            {
+                return startIndex;
+            }
+
             if (ignoreCase)
             {
                 source = source.ToUpper(CultureInfo.InvariantCulture);