Skip to content

Bug when or is used with endOfLine #167

@shreyasminocha

Description

@shreyasminocha

For example,

const regex = VerEx().startOfLine().then('abc').or().then('def').endOfLine();

throws the following error

SyntaxError {
    message: 'Invalid regular expression: /^(?:(?:abc))|(?:(?:def)$/: Unterminated group',
}

This traces to how _suffixes is handled.

or(value) {
    // ...
    this._suffixes = `)${this._suffixes}`;
    // ...
}
endOfLine(enable = true) {
    this._suffixes = enable ? '$' : '';
    // ...
}

When endOfLine is used after or, the initial close paren introduced by or is erased.

I could take a shot at fixing this. How do we want the above example to be interpreted, as /^(?:abc|def)$/gm or as /^(?:abc|def$)/gm? Now that I think of it, this might have been a feature and not a bug due to this ambiguity. If so, it should be documented.

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