diff --git a/src/org/mozilla/javascript/regexp/NativeRegExp.java b/src/org/mozilla/javascript/regexp/NativeRegExp.java index 5e3a2b2af6..c829051460 100644 --- a/src/org/mozilla/javascript/regexp/NativeRegExp.java +++ b/src/org/mozilla/javascript/regexp/NativeRegExp.java @@ -2116,8 +2116,9 @@ && simpleMatch(gData, input, op, program, pc, end, false) < 0) { pc += getOffset(program, pc); break switchStatement; } - if (state.min == 0 && gData.cp == state.index) { - // matched an empty string, that'll get us nowhere + if (state.min == 0 && (gData.cp == state.index || state.max == 0)) { + // matched an empty string or an {0} quantifier, that'll get us + // nowhere result = false; continuationPc = state.continuationPc; continuationOp = state.continuationOp; diff --git a/testsrc/org/mozilla/javascript/tests/Issue1041Test.java b/testsrc/org/mozilla/javascript/tests/Issue1041Test.java new file mode 100644 index 0000000000..9caf529535 --- /dev/null +++ b/testsrc/org/mozilla/javascript/tests/Issue1041Test.java @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.javascript.tests; + +import org.junit.Assert; +import org.junit.Test; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.ScriptableObject; + +public class Issue1041Test { + @Test + public void testQuantifierWithMax0() { + Context cx = Context.enter(); + try { + ScriptableObject scope = cx.initStandardObjects(); + Boolean result = + (Boolean) cx.evaluateString(scope, "/ab{0}c/.test('abc')", "", 1, null); + Assert.assertFalse(result); + + result = (Boolean) cx.evaluateString(scope, "/ab{0}c/.test('ac')", "", 1, null); + Assert.assertTrue(result); + } finally { + Context.exit(); + } + } +}