Skip to content

Commit

Permalink
fix(WebVTT): Tags in the WebVTT subtitle are not parsed (#4960)
Browse files Browse the repository at this point in the history
Fixes #4956
  • Loading branch information
avelad authored and joeyparrish committed Feb 9, 2023
1 parent 762b1e7 commit 15afb4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
9 changes: 4 additions & 5 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,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')) {
Expand Down Expand Up @@ -427,7 +426,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;
}
}
Expand All @@ -438,7 +437,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);
}
}

Expand Down Expand Up @@ -682,7 +681,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;
Expand Down
28 changes: 26 additions & 2 deletions test/text/vtt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,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' +
'<i>Test</i>&amp;',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
});

Expand Down

0 comments on commit 15afb4b

Please sign in to comment.