problem with determination charset end in regexp #863

Closed
springuper opened this Issue Feb 16, 2013 · 1 comment

Comments

Projects
None yet
2 participants

When Lexer encounters a unescaped '[', isCharSet is turned true. But I think there maybe some problem with determination when isCharSet should be turned false. The current code is:

if (isCharSet) {
    if (char === "]") {
        if (this.peek(index - 1) !== "\\" || this.peek(index - 2) === "\\") {
            isCharSet = false;
        }
    }

If regexp is /[ab]/ or /[ab\]/, the code is correct. However, when regexp is /[ab\]]/, the first ']' is escaped, so it doesn't close the charset, and the next ']' does.

I think the correct logic is: if the amount of repeated slashes right before ']' is even, including zero, isCharSet should be turned false.

Member

lukeapage commented Jun 11, 2015

Do you have a reproducible test case for something going wrong? The code looks the same, but...

var a = /[\\\]\</.test("a");

I would expect the above to not error if you were right? I can increase the number of backslashes and an even number passes and an odd number errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment