Skip to content

Commit

Permalink
Guard against empty style properties as a result of trailing semicolo…
Browse files Browse the repository at this point in the history
…ns in inline style attributes. Fixes #19
  • Loading branch information
Munter committed May 31, 2015
1 parent 65d0846 commit 43db5bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ function styleStringToObject(str) {
str.split(';').forEach(function (rule) {
var tuple = rule.split(':').map(function (part) { return part.trim(); });

styles[tuple[0]] = tuple[1];
// Guard against empty touples
if (tuple[0] && tuple[1]) {
styles[tuple[0]] = tuple[1];
}
});

return styles;
Expand Down
10 changes: 10 additions & 0 deletions test/unexpected-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,16 @@ describe('unexpected-dom', function () {
});
}, 'to throw', /to have attributes \{ style: \{ background: 'blue' \} \}/);
});

it('should handle trailing semicolon', function () {
this.body.innerHTML = '<div style="color: red;"></div>';

expect(this.body.firstChild, 'to only have attributes', {
style: {
color: 'red'
}
});
});
});

describe('strict comparison', function () {
Expand Down

0 comments on commit 43db5bc

Please sign in to comment.