Skip to content

Commit

Permalink
Prevent TypeError due to undefined property when parsing styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mdholloway committed Jan 26, 2016
1 parent a792135 commit ec3e338
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function CSSStyleDeclaration(elt) {
// {"margin-left":"5px", "border-style":"solid"}
function parseStyles(s) {
var parser = new parserlib.css.Parser();
var result = {};
var result = { important: {} };
parser.addListener("property", function(e) {
if (e.invalid) return; // Skip errors
result[e.property.text] = e.value.text;
Expand Down
8 changes: 8 additions & 0 deletions test/domino.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,11 @@ exports.contains = function() {
nodeList[0].contains(nodeList[1]).should.equal(false);
nodeList[1].contains(nodeList[0]).should.equal(false);
};

exports.parseImportant = function() {
var html = '<p style="font-family:sans-serif; text-decoration:none !important">foo</p>';
var doc = domino.createDocument(html);
var p = doc.querySelector('p');
p.style.fontFamily.should.equal('sans-serif');
p.style.textDecoration.should.equal('none');
};

0 comments on commit ec3e338

Please sign in to comment.