You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An @supports, @keyframes, @layer or @container block swallows the rule after it #524
CssParser::processCssString() splits the stylesheet with /(.*?)\{(.*?)\}/ (src/Css/CssParser.php:219). MediaQueryProcessor unwraps @media blocks first, but no other block at-rule. For any other, the regex stops at the first inner }, and what is left of the block becomes the start of the next selector.
Measured on gravitypdf at b6a07921, PHP 8.5.4. Each at-rule below is followed by p {color:green}, on <p>:
Before p {color:green}
p
@supports (display:grid) { .a {color:red} }
black: the p rule is lost
@keyframes spin { from {opacity:0} to {opacity:1} }
black
@layer base { h1 {color:red} }
black
@container (min-width:1px) { h1 {color:red} }
black
@media print { … }, @font-face { … }
green
The rules inside @supports and @layer are lost too: @supports (display:block) { p {color:green} } leaves the p black. Framework stylesheets use these; Bootstrap's spinners are @keyframes.
Fix. Before processCssString(), a brace-matching pass removes each @keyframes, @container, @font-feature-values and any other unknown block at-rule whole. It unwraps @supports and @layer, as @media is unwrapped. The alternative is to remove them too, if unwrapping the fallback rules in a @supports not (…) block is judged worse. #536 later replaces this pass with a tokenizer.
Tests. The rule after each at-rule applies, and an @media block inside @supports still works.
Also from #552: statement at-rules.@charset "UTF-8";, @namespace …; and @import …; lose the rule after them too, in a <style> block and in a stylesheet loaded with <link>. Measured on gravitypdf at d660a410: @charset "UTF-8"; p {color:#0f0} leaves the p black. They are not removed before the brace regex (src/Css/CssParser.php:219), so the selector becomes @CHARSET "UTF-8"; P and is dropped. CssLoader fetches an @import but leaves its text in place. Remove all three in the same pass, after CssLoader has fetched the imports.
Tests (also). A rule after each statement at-rule applies.
Activity