Skip to content

Commit

Permalink
Merge pull request #111 from terinjokes/import-uri
Browse files Browse the repository at this point in the history
Parse quoted and unquoted uri @imports. Fixes #108
  • Loading branch information
nzakas committed Mar 13, 2014
2 parents bf9ac73 + fbbcab6 commit 1677b50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/css/Parser.js
Expand Up @@ -259,7 +259,7 @@ Parser.prototype = function(){
tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);

//grab the URI value
uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");

this._readWhitespace();

Expand Down
28 changes: 28 additions & 0 deletions tests/css/Parser.js
Expand Up @@ -1728,6 +1728,34 @@
Assert.areEqual("-moz-inline-stack", event.value.parts[0].text, "Vendor prefixed value -moz-inline-stack is intact.");
});
var result = parser.parse(".foo {\n display: -moz-inline-stack;\n}");
},

"Test @import uri without quotes": function(){
var parser = new Parser({ strict: true});
parser.addListener("import", function(event){
Assert.areEqual("import", event.type);
Assert.areEqual("http://www.yahoo.com", event.uri);
});
var result = parser.parse("@import url(http://www.yahoo.com);");
},


"Test @import uri with quotes": function(){
var parser = new Parser({ strict: true});
parser.addListener("import", function(event){
Assert.areEqual("import", event.type);
Assert.areEqual("http://www.yahoo.com", event.uri);
});
var result = parser.parse("@import url('http://www.yahoo.com');");
},

"Test @import address": function(){
var parser = new Parser();
parser.addListener("import", function(event){
Assert.areEqual("import", event.type);
Assert.areEqual("http://www.yahoo.com", event.uri);
});
var result = parser.parse("@import 'http://www.yahoo.com';");
}
}));

Expand Down

0 comments on commit 1677b50

Please sign in to comment.