diff --git a/lib/text/vtt_text_parser.js b/lib/text/vtt_text_parser.js index b9f36c3856..64a88aea0e 100644 --- a/lib/text/vtt_text_parser.js +++ b/lib/text/vtt_text_parser.js @@ -436,7 +436,9 @@ shaka.text.VttTextParser = class { } const tagEnd = payload.substring(i + 1, end); const tagStart = names.pop(); - if (tagStart === tagEnd) { + if (!tagEnd || !tagStart) { + return payload; + } else if (tagStart === tagEnd) { newPayload += '/' + tagEnd + '>'; i += tagEnd.length + 1; } else { diff --git a/test/text/vtt_text_parser_unit.js b/test/text/vtt_text_parser_unit.js index 845e9f2520..f2b1b51bf8 100644 --- a/test/text/vtt_text_parser_unit.js +++ b/test/text/vtt_text_parser_unit.js @@ -924,6 +924,18 @@ describe('VttTextParser', () => { payload: 'Parse fail 2', nestedCues: [], }, + { + startTime: 100, + endTime: 110, + payload: 'forward slash 1/2 in text', + nestedCues: [], + }, + { + startTime: 110, + endTime: 120, + payload: 'less or more < > in text', + nestedCues: [], + }, ], 'WEBVTT\n\n' + '00:00:20.000 --> 00:00:40.000\n' + @@ -939,7 +951,11 @@ describe('VttTextParser', () => { '00:01:20.000 --> 00:01:30.000\n' + 'Parse fail 1\n\n' + '00:01:30.000 --> 00:01:40.000\n' + - 'Parse fail 2', + 'Parse fail 2\n\n' + + '00:01:40.000 --> 00:01:50.000\n' + + 'forward slash 1/2 in text\n\n' + + '00:01:50.000 --> 00:02:00.000\n' + + 'less or more < > in text', {periodStart: 0, segmentStart: 0, segmentEnd: 0}); });