From b0ffac4f38b64197aedcf61691cfaf97fa1d0025 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Sun, 7 Dec 2003 16:00:38 +0000 Subject: [PATCH] Patch to fix bug 223451 : Check for unbalanced ) and fix for ArrayIndexOutOfBoundsException Check for unbalanced ')' is done differently then in SM since rhino uses recursive version of SM code while fix for ArrayIndexOutOfBoundsException is just a variation of my patch for bug 227705 in SM. git-svn-id: svn://10.0.0.236/trunk@150125 18797224-902f-48f8-a5cc-f745e15eee43 --- .../javascript/regexp/NativeRegExp.java | 87 +++++++++---------- .../javascript/resources/Messages.properties | 3 + 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java b/mozilla/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java index ae15e36e696..09dcb579b85 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/regexp/NativeRegExp.java @@ -20,6 +20,7 @@ * * Contributor(s): * Norris Boyd + * Igor Bukanov * Brendan Eich * Matthias Radestock * @@ -459,7 +460,6 @@ System.out.println(); return true; } - /* * altern: item An alternative is one or more items, * item altern concatenated together. @@ -470,9 +470,9 @@ System.out.println(); RENode tailTerm = null; char[] source = state.cpbegin; while (true) { - if ((state.cp == state.cpend) - || (source[state.cp] == ')') - || (source[state.cp] == '|')) { + if (state.cp == state.cpend || source[state.cp] == '|' + || (state.parenNesting != 0 && source[state.cp] == ')')) + { if (headTerm == null) { state.result = new RENode(REOP_EMPTY); } @@ -943,50 +943,46 @@ System.out.println(); reportError("msg.trail.backslash", ""); return false; } - case '(': + case '(': { + RENode result = null; + termStart = state.cp; + if (state.cp + 1 < state.cpend && src[state.cp] == '?' + && ((c = src[state.cp + 1]) == '=' || c == '!' || c == ':')) { - RENode result = null; - termStart = state.cp; - if ((state.cp < state.cpend) - && (src[state.cp] == '?') - && ( (src[state.cp + 1] == '=') - || (src[state.cp + 1] == '!') - || (src[state.cp + 1] == ':') )) { - ++state.cp; - switch (src[state.cp++]) { - case '=': - result = new RENode(REOP_ASSERT); - /* ASSERT, , ... ASSERTTEST */ - state.progLength += 4; - break; - case '!': - result = new RENode(REOP_ASSERT_NOT); - /* ASSERTNOT, , ... ASSERTNOTTEST */ - state.progLength += 4; - break; - } + state.cp += 2; + if (c == '=') { + result = new RENode(REOP_ASSERT); + /* ASSERT, , ... ASSERTTEST */ + state.progLength += 4; + } else if (c == '!') { + result = new RENode(REOP_ASSERT_NOT); + /* ASSERTNOT, , ... ASSERTNOTTEST */ + state.progLength += 4; } - else { - result = new RENode(REOP_LPAREN); - /* LPAREN, , ... RPAREN, */ - state.progLength += 6; - result.parenIndex = state.parenCount++; - } - if (!parseDisjunction(state)) - return false; - if ((state.cp == state.cpend) - || (src[state.cp] != ')')) { - reportError("msg.unterm.paren", ""); - return false; - } - else - ++state.cp; - if (result != null) { - result.kid = state.result; - state.result = result; - } - break; + } else { + result = new RENode(REOP_LPAREN); + /* LPAREN, , ... RPAREN, */ + state.progLength += 6; + result.parenIndex = state.parenCount++; } + ++state.parenNesting; + if (!parseDisjunction(state)) + return false; + if (state.cp == state.cpend || src[state.cp] != ')') { + reportError("msg.unterm.paren", ""); + return false; + } + ++state.cp; + --state.parenNesting; + if (result != null) { + result.kid = state.result; + state.result = result; + } + break; + } + case ')': + reportError("msg.re.unmatched.right.paren", ""); + return false; case '[': state.result = new RENode(REOP_CLASS); termStart = state.cp; @@ -2903,6 +2899,7 @@ class CompilerState { int cp; int flags; int parenCount; + int parenNesting; int classCount; /* number of [] encountered */ int progLength; /* estimated bytecode length */ RENode result; diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/resources/Messages.properties b/mozilla/js/rhino/src/org/mozilla/javascript/resources/Messages.properties index 3d59d5b2c86..d7e8ec14949 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/resources/Messages.properties +++ b/mozilla/js/rhino/src/org/mozilla/javascript/resources/Messages.properties @@ -197,6 +197,9 @@ msg.bad.range =\ msg.trail.backslash =\ Trailing \\ in regular expression. +msg.re.unmatched.right.paren =\ + unmatched ) in regular expression. + msg.no.regexp =\ Regular expressions are not available.