Skip to content

Commit 2ed026c

Browse files
committed
Fixed bug that caused #createStyleProperty to fail sometimes
1 parent 61cef9c commit 2ed026c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function createStyleProperty(el) {
241241
var output = {};
242242
for (var i = 0; i < style.length; ++i) {
243243
var item = style.item(i);
244-
output[item] = style[item];
244+
output[item] = String(style[item]);
245245
// hack to workaround browser inconsistency with url()
246246
if (output[item].indexOf('url') > -1) {
247247
output[item] = output[item].replace(/\"/g, '')

test/test.js

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ describe('vdom-parser', function () {
196196
expect(output.properties.style['background-image']).to.equal(url);
197197
});
198198

199+
it('should always parse numeric style properties as string', function () {
200+
input = '<div style="z-index:42">test</div>';
201+
output = parser(input);
202+
203+
expect(output.type).to.equal('VirtualNode');
204+
expect(output.tagName).to.equal('DIV');
205+
expect(output.properties.style).to.eql({
206+
'z-index': '42'
207+
});
208+
});
209+
199210
it('should parse base64 encoded styles on node', function () {
200211
var url = 'url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7)';
201212
input = '<div style="background: ' + url + '">test</div>';

0 commit comments

Comments
 (0)