From c83407f0335e6a2839df0fb79af2e66bf37aab06 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 14 May 2014 15:15:42 +0800 Subject: [PATCH] MDL-45545 csslib: Chunking handles commas in media query definitions --- lib/csslib.php | 6 +++--- lib/tests/csslib_test.php | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/csslib.php b/lib/csslib.php index 06612bb5fca..1bcbc0d1d79 100644 --- a/lib/csslib.php +++ b/lib/csslib.php @@ -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++; } diff --git a/lib/tests/csslib_test.php b/lib/tests/csslib_test.php index 8ba3a26a04e..f0f0464385d 100644 --- a/lib/tests/csslib_test.php +++ b/lib/tests/csslib_test.php @@ -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);