diff --git a/src/lib/svg_text_utils.js b/src/lib/svg_text_utils.js index cdabebdf8c3..7150d3a05ed 100644 --- a/src/lib/svg_text_utils.js +++ b/src/lib/svg_text_utils.js @@ -400,7 +400,15 @@ 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) { + Lib.log('Ignoring unexpected end tag .', str); + 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'); + }); }); });