changeset 16214:299e3d0ec77e

8007522: IllegalStateException thrown from String.prototype.search function Reviewed-by: jlaskey
author sundar
date Tue, 05 Feb 2013 21:00:04 +0530
parents 66cb726a76d5
children 92f00bfd6059
files nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java nashorn/test/script/basic/JDK-8007522.js
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Feb 05 18:44:54 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Feb 05 21:00:04 2013 +0530
@@ -675,7 +675,7 @@
         start = matcher.find(start) ? matcher.start() : -1;
 
         if (global) {
-            setLastIndex(matcher.end());
+            setLastIndex(start == -1? -1 : matcher.end());
         }
 
         return start;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8007522.js	Tue Feb 05 21:00:04 2013 +0530
@@ -0,0 +1,13 @@
+/**
+ * JDK-8007522: IllegalStateException thrown from String.prototype.search function
+ *
+ * @test
+ * @run
+ */
+
+var str = "hello";
+// search used to result in IllegalStateException
+if (str.search(/foo/g) != -1) {
+    fail("String.prototype.search failed");
+}
+