Skip to content

Commit

Permalink
Don't transform CSS ID selectors. Fix #2528102.
Browse files Browse the repository at this point in the history
  • Loading branch information
reid committed May 26, 2011
1 parent d7953d5 commit 4c54e62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/com/yahoo/platform/yui/compressor/CssCompressor.java
Expand Up @@ -240,12 +240,17 @@ public void compress(Writer out, int linebreakpos)
m = p.matcher(css);
sb = new StringBuffer();
while (m.find()) {
// Test for AABBCC pattern
if (m.group(3).equalsIgnoreCase(m.group(4)) &&
if (m.group(1).equals("}")) {
// Likely an ID selector. Don't touch.
// #AABBCC is a valid ID. IDs are case-sensitive.
m.appendReplacement(sb, m.group());
} else if (m.group(3).equalsIgnoreCase(m.group(4)) &&
m.group(5).equalsIgnoreCase(m.group(6)) &&
m.group(7).equalsIgnoreCase(m.group(8))) {
// #AABBCC pattern
m.appendReplacement(sb, (m.group(1) + m.group(2) + "#" + m.group(3) + m.group(5) + m.group(7)).toLowerCase());
} else {
// Any other color.
m.appendReplacement(sb, m.group().toLowerCase());
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/preserve-case.css
@@ -0,0 +1,12 @@
#AddAddressForm {
padding: 0;
}
#AddAddressForm .messageBoxNeutral {
padding: 0;
}
#FeedbackMailForm{
padding: 0;
}
#FeedbackMailForm .classe{
margin: 0;
}
1 change: 1 addition & 0 deletions tests/preserve-case.css.min
@@ -0,0 +1 @@
#AddAddressForm{padding:0}#AddAddressForm .messageBoxNeutral{padding:0}#FeedbackMailForm{padding:0}#FeedbackMailForm .classe{margin:0}

0 comments on commit 4c54e62

Please sign in to comment.