From c00aef76210cc7e657a9e8a02cdacdf305c76af3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 12 Nov 2005 12:38:22 +0100 Subject: fix for comment stripping in CSS compression darcs-hash:20051112113822-7ad00-507d694e91f85274266df71b7912690c65bc2b5e.gz --- lib/exe/css.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/exe/css.php') diff --git a/lib/exe/css.php b/lib/exe/css.php index 221e25801..74efe71b6 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -238,9 +238,8 @@ function css_compress($css){ $css = preg_replace('![\r\n\t ]+!',' ',$css); $css = preg_replace('/ ?([:;,{}\/]) ?/','\\1',$css); - // strip comments (ungreedy) - // We keep very small comments to maintain typical browser hacks - $css = preg_replace('#(/\*)((?!\*/).){4,}(\*/)#Us','',$css); + //strip comments through a callback + $css = preg_replace_callback('#(/\*)(.*?)(\*/)#s','css_comment_cb',$css); // shorten colors $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3/", "#\\1\\2\\3",$css); @@ -248,6 +247,17 @@ function css_compress($css){ return $css; } +/** + * Callback for css_compress() + * + * Keeps short comments (< 5 chars) to maintain typical browser hacks + * + * @author Andreas Gohr + */ +function css_comment_cb($matches){ + if(strlen($matches[2]) > 4) return ''; + return $matches[0]; +} //Setup VIM: ex: et ts=4 enc=utf-8 : ?> -- cgit v1.2.3