From: Catrope Date: Tue, 28 Aug 2012 19:35:27 +0000 (-0700) Subject: Work around preg_replace_callback() issue in CSSJanus X-Git-Tag: 1.31.0-rc.0~22557^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=e4fbf314feca13c9a72275dc6f374d46e675c13c;p=lhc%2Fweb%2Fwiklou.git Work around preg_replace_callback() issue in CSSJanus As reported in bug 38294, CSSJanus returns an empty string for some input. This seems to be caused by preg_replace_callback() returning null which, according to the PHP docs, happens "in case of error". Of course there's no way to figure out what the error was :S Work around this by checking for a null return value Change-Id: I5db952bc32f73b94ac13e449d9aa1f8693602dbd --- diff --git a/includes/libs/CSSJanus.php b/includes/libs/CSSJanus.php index e6672b49ad..4ebbc49718 100644 --- a/includes/libs/CSSJanus.php +++ b/includes/libs/CSSJanus.php @@ -268,10 +268,17 @@ class CSSJanus { * @return string */ private static function fixBackgroundPosition( $css ) { - $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage'], + $replaced = preg_replace_callback( self::$patterns['bg_horizontal_percentage'], array( 'self', 'calculateNewBackgroundPosition' ), $css ); - $css = preg_replace_callback( self::$patterns['bg_horizontal_percentage_x'], + if ( $replaced !== null ) { + // Check for null; sometimes preg_replace_callback() returns null here for some weird reason + $css = $replaced; + } + $replaced = preg_replace_callback( self::$patterns['bg_horizontal_percentage_x'], array( 'self', 'calculateNewBackgroundPosition' ), $css ); + if ( $replaced !== null ) { + $css = $replaced; + } return $css; }