瀏覽代碼

[cs] fix String.lastIndexOf for latest spec

Dan Korostelev 6 年之前
父節點
當前提交
4dee0d7a47
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      std/cs/internal/StringExt.hx

+ 8 - 0
std/cs/internal/StringExt.hx

@@ -62,6 +62,14 @@ private typedef NativeString = cs.system.String;
 		//TestBaseTypes.hx@133 fix
 		if (startIndex != null)
 		{
+			// if the number of letters between start index and the length of the string
+			// is less than the length of a searched substring - shift start index to the
+			// left by the difference to avoid OOB access later and save some work
+			var d = me.Length - sIndex - str.Length;
+			if (d < 0) {
+				sIndex += d;
+			}
+
 			var i = sIndex + 1;
 			while (i --> 0)
 			{