Skip to content

Commit

Permalink
fix url parsing with quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
chad3814 committed Jul 9, 2015
1 parent ae78f43 commit b227785
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/parsers.js
Expand Up @@ -220,11 +220,11 @@ exports.parseUrl = function parseUrl(val) {
}
var str = res[1];
// if it starts with single or double quotes, does it end with the same?
if ((str[1] === '"' || str[1] === "'") && str[1] !== str[str.length - 1]) {
if ((str[0] === '"' || str[0] === "'") && str[0] !== str[str.length - 1]) {
return undefined;
}
if (str[1] === '"' || str[1] === "'") {
str = str.substr(1, -1);
if (str[0] === '"' || str[0] === "'") {
str = str.substr(1, str.length - 2);
}

var i;
Expand All @@ -243,6 +243,7 @@ exports.parseUrl = function parseUrl(val) {
break;
}
}

return 'url(' + str + ')';
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "cssstyle",
"description": "CSSStyleDeclaration Object Model implementation",
"keywords": ["CSS", "CSSStyleDeclaration", "StyleSheet"],
"version": "0.2.28",
"version": "0.2.29",
"homepage": "https://github.com/chad3814/CSSStyleDeclaration",
"maintainers": [{
"name": "Chad Walker",
Expand Down
11 changes: 11 additions & 0 deletions tests/tests.js
Expand Up @@ -309,5 +309,16 @@ module.exports = {
style.cssText = 'float: ';
test.ok('' === style.cssText, 'cssText wasn\'t cleared: ' + style.cssText);
test.done();
},
'Make sure url parsing works with quotes': function (test) {
var style = new cssstyle.CSSStyleDeclaration();
test.expect(3);
style.backgroundImage = 'url(http://some/url/here1.png)';
test.ok('url(http://some/url/here1.png)' === style.backgroundImage, 'background-image wasn\'t url(http://some/url/here1.png): ' + style.backgroundImage);
style.backgroundImage = 'url(\'http://some/url/here2.png\')';
test.ok('url(http://some/url/here2.png)' === style.backgroundImage, 'background-image wasn\'t url(http://some/url/here2.png): ' + style.backgroundImage);
style.backgroundImage = 'url("http://some/url/here3.png")';
test.ok('url(http://some/url/here3.png)' === style.backgroundImage, 'background-image wasn\'t url(http://some/url/here3.png): ' + style.backgroundImage);
test.done();
}
};

0 comments on commit b227785

Please sign in to comment.