From 7caf311828d34bee53a18ea4a9a021255be99e00 Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Mon, 27 Jun 2016 16:21:36 -0400 Subject: [PATCH 1/3] Adjust tag regex to catch comment tags. --- lib/parse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 436cdce..243d713 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,5 +1,5 @@ /*jshint -W030 */ -var tagRE = /<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g; +var tagRE = /(?:|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g; var parseTag = require('./parse-tag'); // re-used obj for quick lookups of components var empty = Object.create ? Object.create(null) : {}; From 3b4e3c182adf286eb78c5495bfe7cc3a3c9797d0 Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Mon, 27 Jun 2016 16:22:12 -0400 Subject: [PATCH 2/3] Catch when we're dealing with a comment and just ignore it. --- lib/parse.js | 4 ++++ test/parse.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/parse.js b/lib/parse.js index 243d713..a576f70 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -22,6 +22,10 @@ module.exports = function parse(html, options) { inComponent = false; } } + // check if this is a comment tag. if so, just return. + if (tag.indexOf('\n
Hi
'; + parsed = HTML.parse(html); + t.deepEqual(parsed, [{ + type: 'tag', + name: 'div', + attrs: {}, + voidElement: false, + children: [ + { type: 'text', content: 'Hi'} + ] + }], 'should ignore HTML comments'); t.end(); }); From b56ebb5c8b8fbf6088083aabcbc0ba79bf52f10c Mon Sep 17 00:00:00 2001 From: Ray Di Ciaccio Date: Mon, 27 Jun 2016 16:48:55 -0400 Subject: [PATCH 3/3] Handle multiple & nested comments in a string. --- lib/parse.js | 2 +- test/parse.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index a576f70..d9e94c6 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -1,5 +1,5 @@ /*jshint -W030 */ -var tagRE = /(?:|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g; +var tagRE = /(?:|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g; var parseTag = require('./parse-tag'); // re-used obj for quick lookups of components var empty = Object.create ? Object.create(null) : {}; diff --git a/test/parse.js b/test/parse.js index c85ee5f..bfb34ae 100644 --- a/test/parse.js +++ b/test/parse.js @@ -378,6 +378,24 @@ test('parse', function (t) { { type: 'text', content: 'Hi'} ] }], 'should ignore HTML comments'); + + html = '
Hi
'; + parsed = HTML.parse(html); + t.deepEqual(parsed, [{ + type: 'tag', + name: 'div', + attrs: {}, + voidElement: false, + children: [ + { type: 'text', content: 'Hi '} + ] + },{ + type: 'tag', + name: 'span', + attrs: {}, + voidElement: false, + children: [] + }], 'should ignore nested HTML comments'); t.end(); });