Closed
Description
The public Builder removeModifier(final char pModifier)
method in class Builder
makes use of XOR operation such as modifiers ^= Pattern.CASE_INSENSITIVE;
, which may accidentally switch on the flag and cause opposite result.
This issue has not been discovered in the tests.
E.g. the testWithAnyCaseIsFalse()
method in class BasicFunctionalityUnitTest
calls the withAnyCase(false)
after withAnyCase()
, therefore the modifier is accidentally reset.
@Test
public void testWithAnyCaseIsFalse() {
VerbalExpression testRegex = regex()
.withAnyCase()
.startOfLine()
.then("a")
.withAnyCase(false)
.build();
assertThat(testRegex, not(matchesTo("A")));
}
It would be more robust using bitwise AND with NOT operation. For example,
modifiers &= ~Pattern.CASE_INSENSITIVE;
Metadata
Metadata
Assignees
Labels
No labels