From ec3e33867023887228e538e42129e8c3312e78f7 Mon Sep 17 00:00:00 2001 From: Michael Holloway Date: Mon, 25 Jan 2016 11:58:20 -0500 Subject: [PATCH] Prevent TypeError due to undefined property when parsing styles --- lib/CSSStyleDeclaration.js | 2 +- test/domino.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js index f7cdd42..840f90b 100644 --- a/lib/CSSStyleDeclaration.js +++ b/lib/CSSStyleDeclaration.js @@ -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; diff --git a/test/domino.js b/test/domino.js index 8e7445e..9f5c177 100644 --- a/test/domino.js +++ b/test/domino.js @@ -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 = '

foo

'; + var doc = domino.createDocument(html); + var p = doc.querySelector('p'); + p.style.fontFamily.should.equal('sans-serif'); + p.style.textDecoration.should.equal('none'); +};