Skip to content

Commit df5face

Browse files
authored
Merge pull request #1926 from plotly/fix-invalid-html-input
Ignore bare closing tags in html-like input
2 parents b2e5486 + 5cc607c commit df5face

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/lib/svg_text_utils.js

+8
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,15 @@ function buildSVGText(containerNode, str) {
400400
}
401401

402402
function exitNode(type) {
403+
// A bare closing tag can't close the root node. If we encounter this it
404+
// means there's an extra closing tag that can just be ignored:
405+
if(nodeStack.length === 1) {
406+
Lib.log('Ignoring unexpected end tag </' + type + '>.', str);
407+
return;
408+
}
409+
403410
var innerNode = nodeStack.pop();
411+
404412
if(type !== innerNode.type) {
405413
Lib.log('Start tag <' + innerNode.type + '> doesnt match end tag <' +
406414
type + '>. Pretending it did match.', str);

test/jasmine/tests/svg_text_utils_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -371,5 +371,19 @@ describe('svg+text utils', function() {
371371
opener(2.6) + 'modified' + closer, textCase);
372372
});
373373
});
374+
375+
it('ignores bare closing tags', function() {
376+
var node = mockTextSVGElement('</sub>');
377+
378+
// sub shows up as a zero-width space (u200B) on either side of the 5:
379+
expect(node.text()).toEqual('');
380+
});
381+
382+
it('ignores extra closing tags', function() {
383+
var node = mockTextSVGElement('test<sub>5</sub></sub>more');
384+
385+
// sub shows up as a zero-width space (u200B) on either side of the 5:
386+
expect(node.text()).toEqual('test\u200b5\u200bmore');
387+
});
374388
});
375389
});

0 commit comments

Comments
 (0)