CSSJanus: don't mangle 5+ consecutive numeric values
authorMatmaRex <matma.rex@gmail.com>
Thu, 6 Jun 2013 14:48:42 +0000 (16:48 +0200)
committerMatmaRex <matma.rex@gmail.com>
Thu, 6 Jun 2013 15:29:51 +0000 (17:29 +0200)
Don't mangle 5+ consecutive numeric values in the
'four_notation_quantity' and 'four_notation_color' rules. This
prevents box-shadow rules from being utterly broken in RTL (but still
doesn't flip them properly).

Bug: 45677
Change-Id: I16cb9e171a79c6f299b40fa02908b0c045e3c474

includes/libs/CSSJanus.php
tests/phpunit/includes/libs/CSSJanusTest.php

index fb1e9a4..ac33448 100644 (file)
@@ -113,8 +113,8 @@ class CSSJanus {
                $patterns['rtl_in_url'] = "/{$patterns['lookbehind_not_letter']}(rtl){$patterns['lookahead_for_closing_paren']}/i";
                $patterns['cursor_east'] = "/{$patterns['lookbehind_not_letter']}([ns]?)e-resize/";
                $patterns['cursor_west'] = "/{$patterns['lookbehind_not_letter']}([ns]?)w-resize/";
-               $patterns['four_notation_quantity'] = "/{$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}/i";
-               $patterns['four_notation_color'] = "/(-color\s*:\s*){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}/i";
+               $patterns['four_notation_quantity'] = "/(:\s*){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s*[;}])/i";
+               $patterns['four_notation_color'] = "/(-color\s*:\s*){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s*[;}])/i";
                // The two regexes below are parenthesized differently then in the original implementation to make the
                // callback's job more straightforward
                $patterns['bg_horizontal_percentage'] = "/(background(?:-position)?\s*:\s*[^%]*?)(-?{$patterns['num']})(%\s*(?:{$patterns['quantity']}|{$patterns['ident']}))/";
@@ -257,8 +257,8 @@ class CSSJanus {
         * @return string
         */
        private static function fixFourPartNotation( $css ) {
-               $css = preg_replace( self::$patterns['four_notation_quantity'], '$1$2$7$4$5$6$3', $css );
-               $css = preg_replace( self::$patterns['four_notation_color'], '$1$2$3$8$5$6$7$4', $css );
+               $css = preg_replace( self::$patterns['four_notation_quantity'], '$1$2$3$8$5$6$7$4$9', $css );
+               $css = preg_replace( self::$patterns['four_notation_color'], '$1$2$3$8$5$6$7$4$9', $css );
 
                return $css;
        }
index 632eb52..a1b87f6 100644 (file)
@@ -151,14 +151,11 @@ class CSSJanusTest extends MediaWikiTestCase {
                                '#settings td p strong'
                        ),
                        array(
-                               # Not sure how 4+ values should behave,
-                               # testing to make sure changes are detected
-                               '.foo { x-unknown: 1 2 3 4 5; }',
-                               '.foo { x-unknown: 1 4 3 2 5; }',
+                               // Do not mangle 5 or more values
+                               '.foo { -x-unknown: 1 2 3 4 5; }'
                        ),
                        array(
-                               '.foo { x-unknown: 1 2 3 4 5 6; }',
-                               '.foo { x-unknown: 1 4 3 2 5 6; }',
+                               '.foo { -x-unknown: 1 2 3 4 5 6; }'
                        ),
 
                        // Shorthand / Three notation