Skip to content

Commit

Permalink
Fix parsing of white-space-only div in TTML (#650)
Browse files Browse the repository at this point in the history
A div element with no timing and only whitespace should be considered empty.

Closes #646
  • Loading branch information
tobbee authored and joeyparrish committed Jan 10, 2017
1 parent 292fd9a commit a640f53
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
AdsWizz <*@adswizz.com>
Esteban Dosztal <edosztal@gmail.com>
Google Inc. <*@google.com>
Edgeware AB <*@edgeware.tv>
Itay Kinnrot <Itay.Kinnrot@Kaltura.com>
Jason Palmer <jason@jason-palmer.com>
Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Sanborn Hilland <sanbornh@rogers.com>
Seth Madison <seth@philo.com>
Thomas Stephens <thomas@ustudio.com>
Timothy Drews <tdrews@google.com>
Torbjörn Einarsson <torbjorn.einarsson@edgeware.tv>
Toshihiro Suzuki <t.suzuki326@gmail.com>
Vasanth Polipelli <vasanthap@google.com>
Vignesh Venkatasubramanian <vigneshv@google.com>
6 changes: 3 additions & 3 deletions lib/media/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ shaka.media.TtmlTextParser.parseCue_ = function(

// Disregard empty elements:
// TTML allows for empty elements like <div></div>.
// If cueElement has neither time attributes, nor text,
// don't try to make a cue out of it.
// If cueElement has neither time attributes, nor
// non-whitespace text, don't try to make a cue out of it.
if (!cueElement.hasAttribute('begin') &&
!cueElement.hasAttribute('end') &&
cueElement.textContent == '')
/^\s*$/.test(cueElement.textContent))
return null;

shaka.media.TtmlTextParser.addNewLines_(cueElement);
Expand Down
4 changes: 4 additions & 0 deletions test/media/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ describe('TtmlTextParser', function() {
verifyHelper([], '<tt></tt>');
});

it('supports div with no cues but whitespace', function() {
verifyHelper([], '<tt><body><div> \r\n </div></body></tt>');
});

it('rejects invalid ttml', function() {
errorHelper(shaka.util.Error.Code.INVALID_TTML, '<test></test>');
errorHelper(shaka.util.Error.Code.INVALID_TTML, '');
Expand Down

0 comments on commit a640f53

Please sign in to comment.