Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1041. Handles {0} quantifier with max of zero correctly. #1098

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}