Correct shadow flipping in CSSJanus
authorShahyar <shahyar@gmail.com>
Wed, 30 Jul 2014 22:50:17 +0000 (18:50 -0400)
committerJdlrobson <jrobson@wikimedia.org>
Wed, 30 Jul 2014 23:14:32 +0000 (23:14 +0000)
Was incorrectly assuming values between -1 and 1 were 0
Fixes an issue with mw-ui-input class in RTL mode which
makes use of box shadow.

Change-Id: I13e52467721bc2534e0a7c5245e3380ac43736ef

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

index 4f0651d..30b92c7 100644 (file)
@@ -301,7 +301,7 @@ class CSSJanus {
                // (We can't just negate the value with unary minus due to the units.)
                $flipSign = function ( $cssValue ) {
                        // Don't mangle zeroes
-                       if ( intval( $cssValue ) === 0 ) {
+                       if ( floatval( $cssValue ) === 0.0 ) {
                                return $cssValue;
                        } elseif ( $cssValue[0] === '-' ) {
                                return substr( $cssValue, 1 );
index c8b20d2..407f11a 100644 (file)
@@ -221,6 +221,11 @@ class CSSJanusTest extends MediaWikiTestCase {
                                // Don't mangle zeroes
                                '.foo { text-shadow: orange 0 2px; }'
                        ),
+                       array(
+                               // Make sure floats are not considered zero
+                               '.foo { box-shadow: inset .5em 0 0 white; }',
+                               '.foo { box-shadow: inset -.5em 0 0 white; }',
+                       ),
 
                        // Direction
                        // Note: This differs from the Python implementation,