Skip to content

removeModifier() may switch on the flag #38

Closed
@myjian

Description

@myjian

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions