Skip to content

Commit

Permalink
Ignore style blocks in WebVTT
Browse files Browse the repository at this point in the history
We do not support CSS embedded in WebVTT at this time.  Instead of
failing to parse the cues, skip the style block.

Closes #1104

Change-Id: I3d500ba11afe43e81bbdef9924e4dd9e05db2b85
  • Loading branch information
joeyparrish committed Dec 5, 2017
1 parent bfe41a6 commit 9759edd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/text/vtt_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ shaka.text.VttTextParser.parseCue_ = function(text, timeOffset) {
if (/^NOTE($|[ \t])/.test(text[0]))
return null;

// Skip style blocks.
if (text[0] == 'STYLE')
return null;

var id = null;
var index = text[0].indexOf('-->');
if (index < 0) {
Expand Down
15 changes: 15 additions & 0 deletions test/text/vtt_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,21 @@ describe('VttTextParser', function() {
{ periodStart: 0, segmentStart: 0, segmentEnd: 0 });
});

it('skips style blocks', function() {
verifyHelper(
[
{start: 20, end: 40, payload: 'Test'},
{start: 40, end: 50, payload: 'Test2'}
],
'WEBVTT\n\n' +
'STYLE\n::cue(.cyan) { color: cyan; }\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'Test\n\n' +
'00:00:40.000 --> 00:00:50.000\n' +
'Test2',
{ periodStart: 0, segmentStart: 0, segmentEnd: 0 });
});


/**
* @param {!Array} cues
Expand Down

0 comments on commit 9759edd

Please sign in to comment.