Skip to content

Commit

Permalink
Prevent erroneously tree-shaking keyframe selectors like 'from', 'to'…
Browse files Browse the repository at this point in the history
…, and percentages
  • Loading branch information
westonruter committed Jun 14, 2018
1 parent 764236d commit 519f8c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion includes/sanitizers/class-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ private function fetch_external_stylesheet( $url ) {
private function process_stylesheet( $stylesheet, $options = array() ) {
$parsed = null;
$cache_key = null;
$cache_group = 'amp-parsed-stylesheet-v7';
$cache_group = 'amp-parsed-stylesheet-v8';

$cache_impacting_options = array_merge(
wp_array_slice_assoc(
Expand Down Expand Up @@ -972,6 +972,13 @@ function( $selector ) {
$length = count( $split_stylesheet );
for ( $i = 0; $i < $length; $i++ ) {
if ( $before_declaration_block === $split_stylesheet[ $i ] ) {

// Skip keyframe-selector, which is can be: from | to | <percentage>.
if ( preg_match( '/^((from|to)\b|-?\d+(\.\d+)?%)/i', $split_stylesheet[ $i + 1 ] ) ) {
$stylesheet[] = str_replace( $between_selectors, '', $split_stylesheet[ ++$i ] ) . $split_stylesheet[ ++$i ];
continue;
}

$selectors = explode( $between_selectors . ',', $split_stylesheet[ ++$i ] );
$declaration = $split_stylesheet[ ++$i ];

Expand Down
5 changes: 5 additions & 0 deletions tests/test-amp-style-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ public function get_amp_selector_data() {
'audio{border:solid 1px yellow}',
'amp-audio{border:solid 1px yellow}',
),
'keyframes' => array(
'<div>test</div>',
'span {color:red;} @keyframes foo { from: { opacity:0; } 50% {opacity:0.5} 75%,80% { opacity:0.6 } to { opacity:1 } }',
'@keyframes foo{from:{opacity:0}50%{opacity:.5}75%,80%{opacity:.6}to{opacity:1}}',
),
);
}

Expand Down

0 comments on commit 519f8c7

Please sign in to comment.