--- a/nashorn/src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java Thu Sep 12 14:02:15 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/regexp/RegExpScanner.java Thu Sep 12 17:13:59 2013 +0200
@@ -263,15 +263,6 @@
}
if (atom()) {
- // Check for character classes that never or always match
- if (sb.toString().endsWith("[]")) {
- sb.setLength(sb.length() - 1);
- sb.append("^\\s\\S]");
- } else if (sb.toString().endsWith("[^]")) {
- sb.setLength(sb.length() - 2);
- sb.append("\\s\\S]");
- }
-
quantifier();
return true;
}
@@ -767,7 +758,18 @@
if (classRanges() && ch0 == ']') {
pop(']');
- return commit(1);
+ commit(1);
+
+ // Substitute empty character classes [] and [^] that never or always match
+ if (position == startIn + 2) {
+ sb.setLength(sb.length() - 1);
+ sb.append("^\\s\\S]");
+ } else if (position == startIn + 3 && inNegativeClass) {
+ sb.setLength(sb.length() - 2);
+ sb.append("\\s\\S]");
+ }
+
+ return true;
}
} finally {
inCharClass = false; // no nested character classes in JavaScript