8007522: IllegalStateException thrown from String.prototype.search function
Reviewed-by: jlaskey
--- 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");
+}
+