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

Fix: parse blocks after nested blocks. #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EarlGray
Copy link

@EarlGray EarlGray commented Jul 1, 2019

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!).

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
Copy link

srghma commented Jul 30, 2020

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

@srghma srghma mentioned this pull request Aug 19, 2020
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

Successfully merging this pull request may close these issues.

2 participants