Matmarex has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67264


Change subject: CSSJanus: fix handling for border-radius
......................................................................

CSSJanus: fix handling for border-radius

The values are not "top right bottom left" here, but
"top-left top-right bottom-right bottom-left".

Bug: 49074
Change-Id: I22bc777b59e667aeb36727fdc8e41e8681979128
---
M includes/libs/CSSJanus.php
M tests/phpunit/includes/libs/CSSJanusTest.php
2 files changed, 25 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/64/67264/1

diff --git a/includes/libs/CSSJanus.php b/includes/libs/CSSJanus.php
index ce77864..c20b592 100644
--- a/includes/libs/CSSJanus.php
+++ b/includes/libs/CSSJanus.php
@@ -79,6 +79,7 @@
                'box_shadow' => null,
                'text_shadow1' => null,
                'text_shadow2' => null,
+               'border_radius' => null,
                'bg_horizontal_percentage' => null,
                'bg_horizontal_percentage_x' => null,
        );
@@ -121,6 +122,7 @@
                $patterns['box_shadow'] = 
"/(box-shadow\s*:\s*(?:inset\s*)?){$patterns['possibly_negative_quantity']}/i";
                $patterns['text_shadow1'] = 
"/(text-shadow\s*:\s*){$patterns['color']}(\s*){$patterns['possibly_negative_quantity']}/i";
                $patterns['text_shadow2'] = 
"/(text-shadow\s*:\s*){$patterns['possibly_negative_quantity']}/i";
+               $patterns['border_radius'] = 
"/border-radius{$patterns['four_notation_quantity']}/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']}))/";
@@ -166,6 +168,7 @@
                $css = self::fixLeftAndRight( $css );
                $css = self::fixCursorProperties( $css );
                $css = self::fixFourPartNotation( $css );
+               $css = self::fixBorderRadius( $css );
                $css = self::fixBackgroundPosition( $css );
                $css = self::fixShadows( $css );
 
@@ -306,6 +309,22 @@
        }
 
        /**
+        * Swaps appropriate corners in four-part border-radius rules.
+        * Needs to undo the effect of fixFourPartNotation() on those rules, 
too.
+        *
+        * @param $css string
+        * @return string
+        */
+       private static function fixBorderRadius( $css ) {
+               // Undo four_notation_quantity
+               $css = preg_replace( self::$patterns['border_radius'], 
'border-radius$1$2$3$8$5$6$7$4$9', $css );
+               // Do the real thing
+               $css = preg_replace( self::$patterns['border_radius'], 
'border-radius$1$4$3$2$5$8$7$6$9', $css );
+
+               return $css;
+       }
+
+       /**
         * Flip horizontal background percentages.
         * @param $css string
         * @return string
diff --git a/tests/phpunit/includes/libs/CSSJanusTest.php 
b/tests/phpunit/includes/libs/CSSJanusTest.php
index 8db5444..ecd13f2 100644
--- a/tests/phpunit/includes/libs/CSSJanusTest.php
+++ b/tests/phpunit/includes/libs/CSSJanusTest.php
@@ -137,11 +137,16 @@
                                '.foo { padding: 1px inherit 3px auto; }',
                                '.foo { padding: 1px auto 3px inherit; }'
                        ),
+                       // border-radius assigns different meanings to the 
values
                        array(
                                '.foo { border-radius: .25em 15px 0pt 0ex; }',
-                               '.foo { border-radius: .25em 0ex 0pt 15px; }'
+                               '.foo { border-radius: 15px .25em 0ex 0pt; }'
                        ),
                        array(
+                               '.foo { border-radius: 0px 0px 5px 5px; }',
+                       ),
+                       // Ensure the rule doesn't break other stuff
+                       array(
                                '.foo { x-unknown: a b c d; }'
                        ),
                        array(

-- 
To view, visit https://gerrit.wikimedia.org/r/67264
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22bc777b59e667aeb36727fdc8e41e8681979128
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Matmarex <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to