kneath / kss

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

Fix infinite while loop and reset regex in CoffeeScript #60

Closed gregjopa closed 11 years ago

gregjopa commented 11 years ago

The while loop that iterates over a single pseudo style is causing webkit browsers to crash as discussed in issues #55 and #48. It seems like this while loop's original purpose was to select a pseudo style missed by the first pass through of the test() regex function. When a regex is used in a loop like this it's lastIndex needs to be reset to zero on each iteration otherwise it will continue from the last match-end position (I experience this issue in Firefox but not Chrome).

For example, if you just change the while loop to an if statement like in the pull request in #48 the example Sinatra app won't display the button:disable pseudo element style properly in Firefox because of this issue with lastIndex. Resetting the lastIndex of the regex on each style iteration fixes this issue so this while loop is no longer needed and can be replaced by an if statement.

See this post for more details about this bug with regex lastIndex: http://blog.stevenlevithan.com/archives/es3-regexes-broken

rsahlstrom commented 11 years ago

I agree with this fix and suggested a similar change in #53. This pull requests also fixes the while statement so I'll close mine as this one is more complete.

chibicode commented 11 years ago

:+1:

drusellers commented 11 years ago

:+1:

bangpound commented 11 years ago

:+1: :+1:

benschwarz commented 11 years ago

Confirmed. Merged. Thanks!