diff --git a/lib/utils.js b/lib/utils.js index 98408b3..f541305 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -14,14 +14,14 @@ function createStyleJsonFromString(styleString) { if (singleStyle.length > 2) { singleStyle[1] = singleStyle.slice(1).join(':'); } - + key = camelize(singleStyle[0]); value = singleStyle[1]; if (typeof value === 'string'){ value = value.trim(); } - if (key.length > 0 && value.length > 0) { + if (key && value && key.length > 0 && value.length > 0) { jsonStyles[key] = value; } } diff --git a/test/html-to-react-tests.js b/test/html-to-react-tests.js index de2f7aa..aa4d3ac 100644 --- a/test/html-to-react-tests.js +++ b/test/html-to-react-tests.js @@ -261,6 +261,16 @@ describe('Html2React', function () { assert.equal(reactHtml, htmlExpected); }); + + it('should handle invalid style tag', function () { + var htmlInput = '
'; + var htmlExpected = '
'; + + var reactComponent = parser.parse(htmlInput); + var reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); + + assert.equal(reactHtml, htmlExpected); + }); }); describe('with custom processing instructions', function () {