Bläddra i källkod

[eval] comply with assumed matchSub specification

closes #9333
Simon Krajewski 5 år sedan
förälder
incheckning
5be6a36ac6
2 ändrade filer med 10 tillägg och 1 borttagningar
  1. 3 1
      src/macro/eval/evalStdLib.ml
  2. 7 0
      tests/unit/src/unit/issues/Issue9333.hx

+ 3 - 1
src/macro/eval/evalStdLib.ml

@@ -942,7 +942,9 @@ module StdEReg = struct
 		let this = this vthis in
 		let this = this vthis in
 		let s = decode_string s in
 		let s = decode_string s in
 		let pos = decode_int pos in
 		let pos = decode_int pos in
-		let len = default_int len (String.length s - pos) in
+		let len_default = String.length s - pos in
+		let len = default_int len len_default in
+		let len = if len < 0 then len_default else len in
 		begin try
 		begin try
 			if pos + len > String.length s then raise Not_found;
 			if pos + len > String.length s then raise Not_found;
 			let str = String.sub s 0 (pos + len) in
 			let str = String.sub s 0 (pos + len) in

+ 7 - 0
tests/unit/src/unit/issues/Issue9333.hx

@@ -0,0 +1,7 @@
+package unit.issues;
+
+class Issue9333 extends unit.Test {
+	function test() {
+		t(new EReg("b", "").matchSub("aba", 0, -1));
+	}
+}