From: MatmaRex Date: Thu, 6 Jun 2013 14:48:42 +0000 (+0200) Subject: CSSJanus: don't mangle 5+ consecutive numeric values X-Git-Tag: 1.31.0-rc.0~19466^2 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=3eaad66d633954c46fadab905e87fb98dea07c01;p=lhc%2Fweb%2Fwiklou.git CSSJanus: don't mangle 5+ consecutive numeric values 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 --- diff --git a/includes/libs/CSSJanus.php b/includes/libs/CSSJanus.php index fb1e9a4ce0..ac33448322 100644 --- a/includes/libs/CSSJanus.php +++ b/includes/libs/CSSJanus.php @@ -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; } diff --git a/tests/phpunit/includes/libs/CSSJanusTest.php b/tests/phpunit/includes/libs/CSSJanusTest.php index 632eb52c3e..a1b87f63ae 100644 --- a/tests/phpunit/includes/libs/CSSJanusTest.php +++ b/tests/phpunit/includes/libs/CSSJanusTest.php @@ -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