Tue, 05 Feb 2013 21:00:04 +0530
8007522: IllegalStateException thrown from String.prototype.search function
Reviewed-by: jlaskey
src/jdk/nashorn/internal/objects/NativeRegExp.java | file | annotate | diff | comparison | revisions | |
test/script/basic/JDK-8007522.js | file | annotate | diff | comparison | revisions |
1.1 --- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Tue Feb 05 18:44:54 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Tue Feb 05 21:00:04 2013 +0530 1.3 @@ -675,7 +675,7 @@ 1.4 start = matcher.find(start) ? matcher.start() : -1; 1.5 1.6 if (global) { 1.7 - setLastIndex(matcher.end()); 1.8 + setLastIndex(start == -1? -1 : matcher.end()); 1.9 } 1.10 1.11 return start;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/basic/JDK-8007522.js Tue Feb 05 21:00:04 2013 +0530 2.3 @@ -0,0 +1,13 @@ 2.4 +/** 2.5 + * JDK-8007522: IllegalStateException thrown from String.prototype.search function 2.6 + * 2.7 + * @test 2.8 + * @run 2.9 + */ 2.10 + 2.11 +var str = "hello"; 2.12 +// search used to result in IllegalStateException 2.13 +if (str.search(/foo/g) != -1) { 2.14 + fail("String.prototype.search failed"); 2.15 +} 2.16 +