From d4fc54f8dc68668244b72405b9f972c711b9a868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 3 Feb 2023 11:11:23 +0100 Subject: [PATCH] fix(WebVTT): Tags in the WebVTT subtitle are not parsed (#4960) Fixes https://github.com/shaka-project/shaka-player/issues/4956 --- lib/text/vtt_text_parser.js | 9 ++++----- test/text/vtt_text_parser_unit.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/text/vtt_text_parser.js b/lib/text/vtt_text_parser.js index 49753a2347..7dea95d8f8 100644 --- a/lib/text/vtt_text_parser.js +++ b/lib/text/vtt_text_parser.js @@ -391,8 +391,7 @@ shaka.text.VttTextParser = class { end += timeOffset; // Get the payload. - const payload = VttTextParser.htmlUnescape_( - text.slice(1).join('\n').trim()); + const payload = text.slice(1).join('\n').trim(); let cue = null; if (styles.has('global')) { @@ -450,7 +449,7 @@ shaka.text.VttTextParser = class { const childNode = childNodes[0]; if (childNode.nodeType == Node.TEXT_NODE || childNode.nodeType == Node.CDATA_SECTION_NODE) { - rootCue.payload = payload; + rootCue.payload = VttTextParser.htmlUnescape_(payload); return; } } @@ -461,7 +460,7 @@ shaka.text.VttTextParser = class { rootCue.nestedCues = cues; } else { shaka.log.warning('The cue\'s markup could not be parsed: ', payload); - rootCue.payload = payload; + rootCue.payload = VttTextParser.htmlUnescape_(payload); } } @@ -755,7 +754,7 @@ shaka.text.VttTextParser = class { } if (text.length > 0) { const textCue = nestedCue.clone(); - textCue.payload = text; + textCue.payload = VttTextParser.htmlUnescape_(text); cues.push(textCue); } isFirst = false; diff --git a/test/text/vtt_text_parser_unit.js b/test/text/vtt_text_parser_unit.js index aadc45f950..bbc8d5455f 100644 --- a/test/text/vtt_text_parser_unit.js +++ b/test/text/vtt_text_parser_unit.js @@ -852,11 +852,35 @@ describe('VttTextParser', () => { it('support escaped html payload', () => { verifyHelper( [ - {startTime: 20.1, endTime: 40.505, payload: '"Test & 1"\u{a0}'}, + { + startTime: 20.1, + endTime: 40.505, + payload: '"Test & 1"\u{a0}', + }, + { + startTime: 41, + endTime: 42, + payload: '', + nestedCues: [ + { + startTime: 41, + endTime: 42, + payload: 'Test', + fontStyle: Cue.fontStyle.ITALIC, + }, + { + startTime: 41, + endTime: 42, + payload: '&', + }, + ], + }, ], 'WEBVTT\n\n' + '00:00:20.100 --> 00:00:40.505\n' + - '"Test & 1" ', + '"Test & 1" \n\n' + + '00:00:41.000 --> 00:00:42.000\n' + + 'Test&', {periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0}); });