Skip to content

Commit

Permalink
fix(WebVTT): Tags in the WebVTT subtitle are not parsed (shaka-projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Feb 3, 2023
1 parent ed7a736 commit d4fc54f
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
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
}
}

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

Expand Down

0 comments on commit d4fc54f

Please sign in to comment.