Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
properly rewrite @import rules of the form @import url(…);
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 28, 2014
1 parent 894b784 commit b99a12e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function cloneStyle(style) {
}

var CSS_URL_REGEXP = /(url\()([^)]*)(\))/g;
var CSS_IMPORT_REGEXP = /(@import[\s]*)([^;]*)(;)/g;
var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;

var path = {
resolveUrlsInStyle: function(style) {
Expand Down
1 change: 1 addition & 0 deletions test/html/imports/style-paths-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<style>
@import '../stuff/sheet.css';
@import 'sheet1.css';
@import url(//fonts.googleapis.com/css?family=Open+Sans:300,300italic,600,800|Source+Code+Pro);

.image {
background: url(google.png);
Expand Down
10 changes: 10 additions & 0 deletions test/html/style-paths.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<body>
<div class="red">red</div>
<div class="image" style="height: 20px;"></div>
<div style="font-family: 'Source Code Pro'">Source Code Pro</div>
<script>

document.addEventListener('HTMLImportsLoaded', function() {
Expand All @@ -25,6 +26,15 @@
var a = document.createElement('a');
a.href = 'imports/google.png';
chai.assert.match(getComputedStyle(image).backgroundImage, new RegExp(a.href), 'url in style applied');

if (!HTMLImports.useNative) {
var style = document.querySelector('style');
chai.assert.ok(style.sheet);
chai.assert.equal(style.sheet.cssRules[2].href,
'http://fonts.googleapis.com/css?family=Open+Sans:300,300italic,600,800|Source+Code+Pro',
'@import url() form rule has proper url')
}

done();
});
</script>
Expand Down

0 comments on commit b99a12e

Please sign in to comment.