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): Add support to  , ‎ and ‏ #4920

Merged
merged 2 commits into from
Jan 20, 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: 6 additions & 3 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ shaka.text.VttTextParser = class {
}

/**
* This method converts the HTML entities &, <, >, ", and
* ' in string to their corresponding characters.
* This method converts the HTML entities &, <, >, ", ',
*  , ‎ and ‏ in string to their corresponding characters.
*
* @param {!string} input
* @return {string}
Expand All @@ -955,10 +955,13 @@ shaka.text.VttTextParser = class {
'>': '>',
'"': '"',
''': '\'',
' ': '\u{a0}',
'‎': '\u{200e}',
'‏': '\u{200f}',
};

// Used to match HTML entities and HTML characters.
const reEscapedHtml = /&(?:amp|lt|gt|quot|#(0+)?39);/g;
const reEscapedHtml = /&(?:amp|lt|gt|quot|#(0+)?39|nbsp|lrm|rlm);/g;
const reHasEscapedHtml = RegExp(reEscapedHtml.source);
// This check is an optimization, since replace always makes a copy
if (input && reHasEscapedHtml.test(input)) {
Expand Down
4 changes: 2 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,11 @@ describe('VttTextParser', () => {
it('support escaped html payload', () => {
verifyHelper(
[
{startTime: 20.1, endTime: 40.505, payload: '"Test & 1"'},
{startTime: 20.1, endTime: 40.505, payload: '"Test & 1"\u{a0}'},
],
'WEBVTT\n\n' +
'00:00:20.100 --> 00:00:40.505\n' +
'"Test & 1"',
'"Test & 1" ',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
});

Expand Down