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

Bug when or is used with endOfLine #167

Open
shreyasminocha opened this issue Jul 30, 2018 · 0 comments
Open

Bug when or is used with endOfLine #167

shreyasminocha opened this issue Jul 30, 2018 · 0 comments

Comments

@shreyasminocha
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant