From 6bcf092c2457f637cc5c601fee660c85c45d2ef7 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 2 Aug 2017 11:36:38 -0700 Subject: [PATCH 1/2] Ignore bare closing tags in html-like input --- src/lib/svg_text_utils.js | 5 +++++ test/jasmine/tests/svg_text_utils_test.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index cdabebdf8c3..ad5760cd7d6 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -400,7 +400,12 @@ function buildSVGText(containerNode, str) { } function exitNode(type) { + // A bare closing tag can't close the root node. If we encounter this it + // means there's an extra closing tag that can just be ignored: + if(nodeStack.length === 1) return; + var innerNode = nodeStack.pop(); + if(type !== innerNode.type) { Lib.log('Start tag <' + innerNode.type + '> doesnt match end tag <' + type + '>. Pretending it did match.', str); diff --git a/test/jasmine/tests/svg_text_utils_test.js b/test/jasmine/tests/svg_text_utils_test.js index f0350389cf3..d5552976d87 100644 --- a/test/jasmine/tests/svg_text_utils_test.js +++ b/test/jasmine/tests/svg_text_utils_test.js @@ -371,5 +371,19 @@ describe('svg+text utils', function() { opener(2.6) + 'modified' + closer, textCase); }); }); + + it('ignores bare closing tags', function() { + var node = mockTextSVGElement(''); + + // sub shows up as a zero-width space (u200B) on either side of the 5: + expect(node.text()).toEqual(''); + }); + + it('ignores extra closing tags', function() { + var node = mockTextSVGElement('test5more'); + + // sub shows up as a zero-width space (u200B) on either side of the 5: + expect(node.text()).toEqual('test\u200b5\u200bmore'); + }); }); }); From 5cc607c109d1705abd143470023baf427cabac78 Mon Sep 17 00:00:00 2001 From: Ricky Reusser Date: Wed, 2 Aug 2017 15:33:17 -0700 Subject: [PATCH 2/2] Add log message on unexpected html end tags --- src/lib/svg_text_utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index ad5760cd7d6..7150d3a05ed 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -402,7 +402,10 @@ function buildSVGText(containerNode, str) { function exitNode(type) { // A bare closing tag can't close the root node. If we encounter this it // means there's an extra closing tag that can just be ignored: - if(nodeStack.length === 1) return; + if(nodeStack.length === 1) { + Lib.log('Ignoring unexpected end tag .', str); + return; + } var innerNode = nodeStack.pop();