From a0bc13ef7260d04c65fe1615685d6de5f5954d49 Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Fri, 6 Oct 2017 12:38:07 -0700 Subject: [PATCH 1/2] Fix issue #52 --- lib/utils.js | 4 ++-- test/html-to-react-tests.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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..7e825c3 100644 --- a/test/html-to-react-tests.js +++ b/test/html-to-react-tests.js @@ -259,6 +259,15 @@ describe('Html2React', function () { var reactComponent = parser.parse(htmlInput); var reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); + 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); }); }); From 3bce00a0d5f85bab443f3ce292e35a73d0ade66d Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Sat, 7 Oct 2017 14:49:29 +0200 Subject: [PATCH 2/2] Add newline between tests --- test/html-to-react-tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/html-to-react-tests.js b/test/html-to-react-tests.js index 7e825c3..aa4d3ac 100644 --- a/test/html-to-react-tests.js +++ b/test/html-to-react-tests.js @@ -261,6 +261,7 @@ describe('Html2React', function () { assert.equal(reactHtml, htmlExpected); }); + it('should handle invalid style tag', function () { var htmlInput = '
'; var htmlExpected = '
';