MDL-45545 csslib: Chunking handles commas in media query definitions
authorFrederic Massart <fred@moodle.com>
Wed, 14 May 2014 07:15:42 +0000 (15:15 +0800)
committerDan Poltawski <dan@moodle.com>
Tue, 20 May 2014 04:21:45 +0000 (12:21 +0800)
lib/csslib.php
lib/tests/csslib_test.php

index 4597d8a..2bd94d6 100644 (file)
@@ -176,9 +176,9 @@ function css_chunk_by_selector_count($css, $importurl, $maxselectors = 4095, $bu
             }
         }
 
-        // Let's count the number of selectors, but only if we are not in a rule as they
-        // can contain commas too.
-        if (!$inrule && $char === ',') {
+        // Let's count the number of selectors, but only if we are not in a rule, or in
+        // the definition of a media query, as they can contain commas too.
+        if (!$mediacoming && !$inrule && $char === ',') {
             $selectorcount++;
         }
 
index 099df9b..5a9f02c 100644 (file)
@@ -1176,6 +1176,12 @@ CSS;
         $this->assertCount(1, $chunks);
         $this->assertSame('@media (min-width: 980px) { .a,.b{} }', $chunks[0]);
 
+        // Test media queries, with commas.
+        $css = '.a{} @media (min-width: 700px), handheld and (orientation: landscape) { .b{} }';
+        $chunks = css_chunk_by_selector_count($css, 'styles.php?type=test', 2);
+        $this->assertCount(1, $chunks);
+        $this->assertSame($css, $chunks[0]);
+
         // Test special rules.
         $css = 'a,b{ background-image: linear-gradient(to bottom, #ffffff, #cccccc);}d,e{}';
         $chunks = css_chunk_by_selector_count($css, 'styles.php?type=test', 2);