From 89bc655730d858861b07335f2fdd4f8f5a1945f4 Mon Sep 17 00:00:00 2001 From: Keith Clark Date: Tue, 21 Jun 2011 18:49:44 +0100 Subject: [PATCH] Big fix: .htc behavior urls incorrectly resolved against CSS url. Fixes CSS3PIE issue. Test Added. --- changelog.txt | 3 ++- selectivizr.js | 6 +++--- tests/master/css/master.css | 3 +++ tests/master/htc/test.htc | 6 ++++++ tests/master/index.html | 4 ++++ 5 files changed, 18 insertions(+), 4 deletions(-) mode change 100644 => 100755 changelog.txt mode change 100644 => 100755 selectivizr.js mode change 100644 => 100755 tests/master/css/master.css create mode 100755 tests/master/htc/test.htc mode change 100644 => 100755 tests/master/index.html diff --git a/changelog.txt b/changelog.txt old mode 100644 new mode 100755 index 9bd8945..7447720 --- a/changelog.txt +++ b/changelog.txt @@ -4,7 +4,8 @@ selectivizr - change log Current Build ------------- - * BUG - resolveUrl() fails to resolve protocol relative urls + * BUG - behaviors (.htc files) are now ignored when processing urls. Fixes "CSS3PIE" issue + * BUG - resolveUrl() fails to resolve protocol relative urls. Fixes "AddThis" issue * NEW - expose selectiviz'd cssText through styleSheet object via 'rawCssText' expando property * BUG - incorrect parsing of @media blocks (fixes respondJS compatibility issue) * BUG - resolveUrl() incorrectly fails external assets urls for violating the same origin policy diff --git a/selectivizr.js b/selectivizr.js old mode 100644 new mode 100755 index ac820b7..b9b6c0a --- a/selectivizr.js +++ b/selectivizr.js @@ -70,7 +70,7 @@ References: // Stylesheet parsing regexp's var RE_COMMENT = /(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)\s*?/g; var RE_IMPORT = /@import\s*(?:(?:(?:url\(\s*(['"]?)(.*)\1)\s*\))|(?:(['"])(.*)\3))\s*([^;]*);/g; - var RE_ASSET_URL = /\burl\(\s*(["']?)(?!data:)([^"')]+)\1\s*\)/g; + var RE_ASSET_URL = /(behavior\s*?:\s*)?\burl\(\s*(["']?)(?!data:)([^"')]+)\2\s*\)/g; var RE_PSEUDO_STRUCTURAL = /^:(empty|(first|last|only|nth(-last)?)-(child|of-type))$/; var RE_PSEUDO_ELEMENTS = /:(:first-(?:line|letter))/g; var RE_SELECTOR_GROUP = /((?:^|(?:\s*})+)(?:\s*@media[^{]+{)?)\s*([^\{]*?[\[:][^{]+)/g; @@ -446,9 +446,9 @@ References: var cssText = parseStyleSheet(resolveUrl(importUrl || importUrl2, url)); return (media) ? "@media " + media + " {" + cssText + "}" : cssText; }). - replace(RE_ASSET_URL, function( match, quoteChar, assetUrl ) { + replace(RE_ASSET_URL, function( match, isBehavior, quoteChar, assetUrl ) { quoteChar = quoteChar || EMPTY_STRING; - return " url(" + quoteChar + resolveUrl(assetUrl, url, true) + quoteChar + ") "; + return isBehavior ? match : " url(" + quoteChar + resolveUrl(assetUrl, url, true) + quoteChar + ") "; }); } return EMPTY_STRING; diff --git a/tests/master/css/master.css b/tests/master/css/master.css old mode 100644 new mode 100755 index acf1e4b..6089ff1 --- a/tests/master/css/master.css +++ b/tests/master/css/master.css @@ -53,6 +53,9 @@ body { background: #c00 url("https://github.com/keithclark/selectivizr/raw/master/tests/master/css/nested/test.png"); } +#url-htc { + behavior: url(htc/test.htc); +} /* pseudo-class tests ------------------------------------------------------------------------------------ */ diff --git a/tests/master/htc/test.htc b/tests/master/htc/test.htc new file mode 100755 index 0000000..6be26a4 --- /dev/null +++ b/tests/master/htc/test.htc @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/tests/master/index.html b/tests/master/index.html old mode 100644 new mode 100755 index ba256c4..cb98f25 --- a/tests/master/index.html +++ b/tests/master/index.html @@ -137,6 +137,10 @@

url syntax tests

background: url("http://domain/test.png") Testing css property referring to an asset on an external domain + + background: url("js/test.htc") + Testing behavior url resolves relative to the document url +

iframe tests