Permalink
Browse files

css-escapes: Fix IE issues #11 and #12

Only escape `_` at the start of an identifier. (#11)
Escape `:` as `\3a ` instead of `\:` for better IE < 8 support. (#12)
  • Loading branch information...
1 parent a52a9fe commit 699c9b13d67546c272841af3e6e18a44d730db68 @mathiasbynens committed Mar 30, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 css-escapes/eff.js
View
@@ -92,9 +92,10 @@
value = '\\' + charCode.toString(16) + ' ';
} else {
// \r is already tokenized away at this point
- if (/[\t\n\v\f]/.test(character)) {
+ // `:` can be escaped as `\:`, but that fails in IE < 8
+ if (/[\t\n\v\f:]/.test(character)) {
value = '\\' + charCode.toString(16) + ' ';
- } else if (/[ !"#$%&'()*+,./:;<=>?@\[\\\]^_`{|}~]/.test(character)) {
+ } else if (/[ !"#$%&'()*+,./;<=>?@\[\\\]^`{|}~]/.test(character)) {
value = '\\' + character;
} else {
value = character;
@@ -103,6 +104,9 @@
output += value;
}
+ if (/^_/.test(output)) { // Prevent IE6 from ignoring the rule altogether
+ output = '\\_' + output.slice(1);
+ }
if (/^-[-\d]/.test(output)) {
output = '\\-' + output.slice(1);
}
@@ -155,7 +159,8 @@
escapeResult = cssEscape(value, checkbox.checked),
cssValue = '#' + escapeResult.output,
surrogatePairCount = escapeResult.surrogatePairCount,
- qsaValue = doubleSlash(cssValue),
+ // IE 8 can handle leading underscores; no point in escaping them here:
+ qsaValue = doubleSlash(cssValue.replace(/^#\\_/, '#_')),
jsValue = (checkbox.checked ? jsEscape(value) : doubleSlash(value)).replace(/<\/script/g, '<\\/script'), // http://mths.be/etago
link = '#' + (+checkbox.checked) + encode(value);
whitespace.className = /\s/.test(value) ? 'show' : '';

0 comments on commit 699c9b1

Please sign in to comment.