Ver Fonte

[cs] fix Array.indexOf with startIndex greater than length, test it (let's hear from travis if only c# is affected)

Dan Korostelev há 11 anos atrás
pai
commit
67599f255e
2 ficheiros alterados com 5 adições e 0 exclusões
  1. 4 0
      std/cs/_std/Array.hx
  2. 1 0
      tests/unit/unitstd/Array.unit.hx

+ 4 - 0
std/cs/_std/Array.hx

@@ -95,6 +95,10 @@ import cs.NativeArray;
 			i += len;
 			if (i < 0) i = 0;
 		}
+		else if (i >= len)
+		{
+			return -1;
+		}
 		return cs.system.Array._IndexOf(__a, x, i, len - i);
 	}
 

+ 1 - 0
tests/unit/unitstd/Array.unit.hx

@@ -210,6 +210,7 @@ a == [i0, i1];
 [1, 10, 10, 1].indexOf(10, 2) == 2;
 [1, 10, 10, 1].indexOf(10, 3) == -1;
 [1, 10, 10, 1].indexOf(10, 4) == -1;
+[1, 10, 10, 1].indexOf(10, 5) == -1;
 [1, 10, 10, 1].indexOf(10, -1) == -1;
 [1, 10, 10, 1].indexOf(10, -2) == 2;
 [1, 10, 10, 1].indexOf(10, -3) == 1;