Skip to content

Commit

Permalink
fix(WebVTT): Add support to  , ‎ and ‏ (shaka-project#4920)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jan 20, 2023
1 parent 2043af0 commit 726ef42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/text/vtt_text_parser.js
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
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

0 comments on commit 726ef42

Please sign in to comment.