Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private Op compile(Token tok, Op next, boolean reverse) {
* @return true if the target is matched to this regular expression.
*/
public boolean matches(char[] target) {
return this.matches(target, 0, target .length , (Match)null);
return this.matches(target, 0, target .length , null);
}

/**
Expand All @@ -659,7 +659,7 @@ public boolean matches(char[] target) {
* @return true if the target is matched to this regular expression.
*/
public boolean matches(char[] target, int start, int end) {
return this.matches(target, start, end, (Match)null);
return this.matches(target, start, end, null);
}

/**
Expand Down Expand Up @@ -833,7 +833,7 @@ else if (this.firstChar != null) {
* @return true if the target is matched to this regular expression.
*/
public boolean matches(String target) {
return this.matches(target, 0, target .length() , (Match)null);
return this.matches(target, 0, target .length() , null);
}

/**
Expand All @@ -845,7 +845,7 @@ public boolean matches(String target) {
* @return true if the target is matched to this regular expression.
*/
public boolean matches(String target, int start, int end) {
return this.matches(target, start, end, (Match)null);
return this.matches(target, start, end, null);
}

/**
Expand Down Expand Up @@ -1023,7 +1023,7 @@ else if (this.firstChar != null) {
*/
private int match(Context con, Op op, int offset, int dx, int opts) {
final ExpressionTarget target = con.target;
final Stack opStack = new Stack();
final Stack<Op> opStack = new Stack<>();
final IntStack dataStack = new IntStack();
final boolean isSetIgnoreCase = isSet(opts, IGNORE_CASE);
int retValue = -1;
Expand Down Expand Up @@ -1091,7 +1091,7 @@ private int match(Context con, Op op, int offset, int dx, int opts) {
returned = true;
break;
}
int ch = target.charAt(offset);
int ch = target.charAt(o1);
if (REUtil.isHighSurrogate(ch) && o1+dx < con.limit && o1+dx >=0) {
o1 += dx;
ch = REUtil.composeFromSurrogates(ch, target.charAt(o1));
Expand Down Expand Up @@ -1304,7 +1304,7 @@ else if (cop.no != null) {
return retValue;
}

op = (Op) opStack.pop();
op = opStack.pop();
offset = dataStack.pop();

switch (op.type) {
Expand Down Expand Up @@ -1534,7 +1534,7 @@ private static final int getWordType(ExpressionTarget target, int begin, int end
* @return true if the target is matched to this regular expression.
*/
public boolean matches(CharacterIterator target) {
return this.matches(target, (Match)null);
return this.matches(target, null);
}


Expand Down Expand Up @@ -2401,8 +2401,7 @@ private static boolean isWordChar(int ch) { // Legacy word characters
if (ch <= '9') return true;
if (ch < 'A') return false;
if (ch <= 'Z') return true;
if (ch < 'a') return false;
return true;
return ch >= 'a';
}

private static boolean matchIgnoreCase(int chardata, int ch) {
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/misc/checkin/RegularExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Random;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class RegularExpressionTest {
Expand All @@ -31,6 +32,18 @@ void testLongString() {
assertTrue(regex.matches(rnd));
}

@Test
void testLookbehindRangeAtInputEnd() {
// a lookbehind containing a character class, evaluated at the end of the
// input, used to read one character past the string in the RANGE op and
// throw StringIndexOutOfBoundsException
assertTrue(new RegularExpression("(?<=[a-c])$").matches("abc"));
assertTrue(new RegularExpression(".*(?<=[0-9])").matches("ab9"));
// the same off-by-one read also returned the wrong match result: the char
// before the lookbehind is 'x', not in [a-c], so this must not match
assertFalse(new RegularExpression("x(?<=[a-c])").matches("xc"));
}


private static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final Random rnd = new Random();
Expand Down
Loading