Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(WebVTT): Tags in the WebVTT subtitle are not parsed #4960

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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