CSS aggregation removes ie-mac hack which is being used in defaults.css.

// from defaults.css
$contents = <<<EOS
.clearfix {
  display: inline-block;
}

/* Hides from IE-mac \*/
* html .clearfix {
  height: 1%;
}
.clearfix {
  display: block;
}
/* End hide from IE-mac */

EOS;

// from drupal_load_stylesheet_content()
    $contents = preg_replace('{
      (?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/)  # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it.
                                            # The added backshlash does not affect the effectiveness of the hack.
      }x', '\1\\\\\2', $contents);    
    $contents = preg_replace('<
      \s*([@{}:;,]|\)\s|\s\()\s* |          # Remove whitespace around separators, but keep space around parentheses.
      /\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ |    # Remove comments that are not CSS hacks.
      >x', '\1', $contents);

echo $contents;

Result:

.clearfix{display:inline-block;}/* Hides from IE-mac \*/ * html .clearfix{height:1%;}.clearfix{display:block;} 

Comments

casey’s picture

Assigned: Unassigned » casey
damien tournoud’s picture

Status: Active » Closed (duplicate)

I just reopened the other one.

Tri’s picture

Title: CSS aggregation removes ie-mac hack which is being used in defaults.css » CSS aggregation removes multi-line ie-mac hacks when the hack rules contain a star
Status: Closed (duplicate) » Active

The problem is here

    $contents = preg_replace('{
      (?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/)  # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it.
                                            # The added backshlash does not affect the effectiveness of the hack.
      }x', '\1\\\\\2', $contents); 

It has to be rewritten so it will match multi-line blocks ever if they contain a star.

I will look into this and get back.

Tri’s picture

Status: Active » Needs review
StatusFileSize
new934 bytes

The attached patch fixes it. Now it doesn't strip the end ie-mac hack comment even if the hack css rules contain a star.

casey’s picture

StatusFileSize
new2.83 KB
new2.69 KB

This still fails on the ie-mac feed hack:

/* feed to ie5/mac \*//*/
@import "ie5mac.css";
/* necessary comment */

I created another version and used this file to test against: http://code.google.com/p/minify/source/browse/trunk/min_unit_tests/_test.... It only fails on nav4 hack (nobody uses that one anymore) and Tantek's midpass hack (which is too complicated anyway).

Also added some extra whitespace removals.

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

StatusFileSize
new5.27 KB

Forgot to update tests.

Also improved the code, comments in strings are handled correctly now (and Tantek's midpass hack does pass).

casey’s picture

Status: Needs work » Needs review
rfay’s picture

subscribing

casey’s picture

StatusFileSize
new12.16 KB

+ test and some improvements.

Test in this patch does however failes due to #646862: CSS aggregate removes @import rules when not properly resolved.

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

In #641472: Fix CSS Aggregator, I am trying to fix all issues regarding CSS aggregation.

casey’s picture

Status: Needs work » Needs review

Ok, back to patch of Tri in #5. The patch works.

The IE-Mac CSS hack applies to IE5/Win and IE/Mac 5.0 & 5.1. The hack doesn't apply to IE/Mac 5.2. Latest version is 5.2.3 and originated from June 16, 2003.

The multi-line IE-Mac CSS hack is being used in modules/system/defaults.css. Current CSS aggregation removes the comments from that stylesheet. If support for that browsers should be kept, patch in #5 should go in.

But maybe we should just remove that hack from defaults.css.

Tri’s picture

Status: Needs review » Closed (duplicate)

I have found out that patch from #5 removes the multi-line ie-mac hack end comment when the hack rules contain a / also, so it's getting too complex to solve it through regexps.

Meanwhile, Gábor Hojtsy suggests here #444228: Optimize CSS option causes php cgi to segfault in pcre function "match" (#89) that any action about this issue should take place at that thread. So I am marking this (again) as duplicate of #444228: Optimize CSS option causes php cgi to segfault in pcre function "match", and I will post a new patch there.