8175362: StringIndexOutOfBoundsException from /.*((a[^a]+){2})c$/.exec('ababc')
Reviewed-by: sundar, hannesw
This commit is contained in:
parent
865f838bf1
commit
4d2272b872
@ -102,6 +102,8 @@ final class Analyser extends Parser {
|
||||
|
||||
env.memNodes = null;
|
||||
|
||||
new ArrayCompiler(this).compile();
|
||||
|
||||
if (regex.numRepeat != 0 || regex.btMemEnd != 0) {
|
||||
regex.stackPopLevel = StackPopLevel.ALL;
|
||||
} else {
|
||||
|
@ -127,31 +127,17 @@ public final class Regex implements RegexState {
|
||||
this.caseFoldFlag = caseFoldFlag;
|
||||
this.warnings = warnings;
|
||||
|
||||
this.analyser = new Analyser(new ScanEnvironment(this, syntax), chars, p, end);
|
||||
this.analyser.compile();
|
||||
new Analyser(new ScanEnvironment(this, syntax), chars, p, end).compile();
|
||||
|
||||
this.warnings = null;
|
||||
}
|
||||
|
||||
public synchronized MatcherFactory compile() {
|
||||
if (factory == null && analyser != null) {
|
||||
new ArrayCompiler(analyser).compile();
|
||||
analyser = null; // only do this once
|
||||
}
|
||||
assert factory != null;
|
||||
return factory;
|
||||
}
|
||||
|
||||
public Matcher matcher(final char[] chars) {
|
||||
return matcher(chars, 0, chars.length);
|
||||
}
|
||||
|
||||
public Matcher matcher(final char[] chars, final int p, final int end) {
|
||||
MatcherFactory matcherFactory = factory;
|
||||
if (matcherFactory == null) {
|
||||
matcherFactory = compile();
|
||||
}
|
||||
return matcherFactory.create(this, chars, p, end);
|
||||
return factory.create(this, chars, p, end);
|
||||
}
|
||||
|
||||
public WarnCallback getWarnings() {
|
||||
@ -309,7 +295,6 @@ public final class Regex implements RegexState {
|
||||
}
|
||||
|
||||
public String dumpByteCode() {
|
||||
compile();
|
||||
return new ByteCodePrinter(this).byteCodeListToString();
|
||||
}
|
||||
|
||||
|
36
nashorn/test/script/basic/JDK-8175362.js
Normal file
36
nashorn/test/script/basic/JDK-8175362.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* JDK-8175362 : StringIndexOutOfBoundsException from /.*((a[^a]+){2})c$/.exec('ababc')
|
||||
*
|
||||
* @test
|
||||
* @run
|
||||
*/
|
||||
|
||||
var regexp;
|
||||
|
||||
regexp = new RegExp(".*((a[^a]+){2})c$");
|
||||
print(regexp.exec("ababc"));
|
||||
regexp = new RegExp("(a[^a]+){3}");
|
||||
print(regexp.exec("ababc"));
|
2
nashorn/test/script/basic/JDK-8175362.js.EXPECTED
Normal file
2
nashorn/test/script/basic/JDK-8175362.js.EXPECTED
Normal file
@ -0,0 +1,2 @@
|
||||
ababc,abab,ab
|
||||
null
|
Loading…
Reference in New Issue
Block a user