Browse Source

[php] fix String.lastIndexOf(s, startIndex) for negative `startIndex` exceeding string length

Aleksandr Kuzmenko 6 years ago
parent
commit
f1c8c59077
1 changed files with 8 additions and 3 deletions
  1. 8 3
      std/php/Boot.hx

+ 8 - 3
std/php/Boot.hx

@@ -775,9 +775,14 @@ private class HxString {
 		if(start == null) {
 			start = 0;
 		} else {
-			start = start - str.length;
-			if(start > 0) {
-				start = 0;
+			var length = str.length;
+			if(start >= 0) {
+				start = start - length;
+				if(start > 0) {
+					start = 0;
+				}
+			} else if(start < -length) {
+				start = -length;
 			}
 		}
 		var index:EitherType<Int,Bool> = if(search == '') {