Skip to content

Commit

Permalink
Fix issue #1041. Handles {0} quantifier with max of zero correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxisTekfield committed Nov 27, 2021
1 parent cb8d5f0 commit 5acc124
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/org/mozilla/javascript/regexp/NativeRegExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions testsrc/org/mozilla/javascript/tests/Issue1041Test.java
Original file line number Diff line number Diff line change
@@ -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')", "<eval>", 1, null);
Assert.assertFalse(result);

result = (Boolean) cx.evaluateString(scope, "/ab{0}c/.test('ac')", "<eval>", 1, null);
Assert.assertTrue(result);
} finally {
Context.exit();
}
}
}

0 comments on commit 5acc124

Please sign in to comment.