CSSJanus: Fix handling of CSS3 color syntaxes
authorMatmaRex <matma.rex@gmail.com>
Thu, 6 Jun 2013 15:33:37 +0000 (17:33 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 4 Jul 2013 03:30:26 +0000 (05:30 +0200)
The 'color' rule, and by extension 'four_notation_color' too,
only understood #rrggbb and named colors. Extend it to match
rgb[a](...) and hsl[a](...) syntaxes as well.

This makes usage of rgb(a)/hsl(a) syntax in declarations like
'border-color: a b c d;' be interpreted and flipped correctly.

Change-Id: I218a9aa55a86b3d955b92375c1a209fdde312138

RELEASE-NOTES-1.22
includes/libs/CSSJanus.php
tests/phpunit/includes/libs/CSSJanusTest.php

index 8bf680b..63453c5 100644 (file)
@@ -169,6 +169,7 @@ production.
   backwards-compatible in all reasonable cases (uses of the __TOC__ magic word,
   the #toc CSS id and the .toc CSS class). However, particularly bad abuse of
   the id or the class can possibly break.
+* CSSJanus now supports rgb, hsl, rgba, and hsla color syntaxes.
 
 === API changes in 1.22 ===
 * (bug 25553) The JSON output formatter now leaves forward slashes unescaped
index ac33448..46236cd 100644 (file)
@@ -96,7 +96,7 @@ class CSSJanus {
                $patterns['ident'] = "-?{$patterns['nmstart']}{$patterns['nmchar']}*";
                $patterns['quantity'] = "{$patterns['num']}(?:\s*{$patterns['unit']}|{$patterns['ident']})?";
                $patterns['possibly_negative_quantity'] = "((?:-?{$patterns['quantity']})|(?:inherit|auto))";
-               $patterns['color'] = "(#?{$patterns['nmchar']}+)";
+               $patterns['color'] = "(#?{$patterns['nmchar']}+|(?:rgba?|hsla?)\([ \d.,%-]+\))";
                $patterns['url_chars'] = "(?:{$patterns['url_special_chars']}|{$patterns['nonAscii']}|{$patterns['escape']})*";
                $patterns['lookahead_not_open_brace'] = "(?!({$patterns['nmchar']}|\r?\n|\s|#|\:|\.|\,|\+|>)*?{)";
                $patterns['lookahead_not_closing_paren'] = "(?!{$patterns['url_chars']}?{$patterns['valid_after_uri_chars']}\))";
index a1b87f6..e6432a9 100644 (file)
@@ -150,6 +150,21 @@ class CSSJanusTest extends MediaWikiTestCase {
                        array(
                                '#settings td p strong'
                        ),
+                       array(
+                               // Color names
+                               '.foo { border-color: red green blue white }',
+                               '.foo { border-color: red white blue green }',
+                       ),
+                       array(
+                               // Color name, hexdecimal, RGB & RGBA
+                               '.foo { border-color: red #f00 rgb(255, 0, 0) rgba(255, 0, 0, 0.5) }',
+                               '.foo { border-color: red rgba(255, 0, 0, 0.5) rgb(255, 0, 0) #f00 }',
+                       ),
+                       array(
+                               // Color name, hexdecimal, HSL & HSLA
+                               '.foo { border-color: red #f00 hsl(0, 100%, 50%) hsla(0, 100%, 50%, 0.5) }',
+                               '.foo { border-color: red hsla(0, 100%, 50%, 0.5) hsl(0, 100%, 50%) #f00 }',
+                       ),
                        array(
                                // Do not mangle 5 or more values
                                '.foo { -x-unknown: 1 2 3 4 5; }'