kneath / kss

A methodology for documenting CSS and generating styleguides.
warpspire.com/kss
MIT License
4.04k stars 275 forks source link

Resets lastIndex of pseudos before reuse #53

Closed rsahlstrom closed 11 years ago

rsahlstrom commented 11 years ago

When a regex is used with the g operator in JavaScript, it keeps track of where the last match was found for future use. When a new test is ran on that same regex, the pattern continues searching from the lastIndex which means patterns before the lastIndex are not used when testing. This can result in strings that should have matched the regex to be reported as not matching.

Adds a line to reset the lastIndex of pseudos to zero before each test is ran to make sure all patterns are tested against every single time.

Additional information about the problem can be found at:

http://blog.stevenlevithan.com/archives/fixing-javascript-regexp

rsahlstrom commented 11 years ago

Here's another article that's a bit clearer on the problem:

http://blog.thatscaptaintoyou.com/strange-behavior-of-the-global-regex-flag/

rsahlstrom commented 11 years ago

Pull request #60 has a more complete solution.