yesodweb / css-text

CSS parser and renderer.
MIT License
16 stars 8 forks source link

Fix: parse blocks after nested blocks. #14

Open EarlGray opened 5 years ago

EarlGray commented 5 years ago

This is a stopgap measure to enable this library to parse e.g. Bootstrap 4.3.1.

The problem can be illustrated by the example:

1 | @media {
2 |    foo {}
3 | }
4 | bar {}

nestedParse parses the first block inside a nested block on its own, (in this case: foo {}), then uses blocksParser to read the rest. The previous version of blocksParser is too greedy and consumes everything until the next '{'. In this case: } bar becomes a "selector", the bar block becomes the next "subblock" of @media and the "absent" '}' for @media { fails parsing.

This patch uses '}' as a character that is highly unlikely to happen inside a selector (although it's still possible, e.g. [attr="}"]) and highly likely to terminate one-block @-blocks.

Previously, css-text failed on Bootstrap 4.3.1 at the 94th block, now it can parse all of its >1200 blocks (not completely correctly, but rather fine for CSS and such a tiny library!).

srghma commented 4 years ago

works awesome, fixed my problem with @keyframes (the css after @keyframes was not read)