From 9e351474b64c3bbe3f1c66aeefedcdf0010757ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Einarsson?= Date: Tue, 10 Jan 2017 18:50:48 +0100 Subject: [PATCH] Fix parsing of white-space-only div in TTML (#650) A div element with no timing and only whitespace should be considered empty. Closes #646 --- AUTHORS | 1 + CONTRIBUTORS | 1 + lib/media/ttml_text_parser.js | 6 +++--- test/media/ttml_text_parser_unit.js | 4 ++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9be1dce16b..1bd129c129 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,6 +16,7 @@ AdsWizz <*@adswizz.com> Esteban Dosztal Google Inc. <*@google.com> +Edgeware AB <*@edgeware.tv> Itay Kinnrot Jason Palmer Jesper Haug Karsrud diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 75ce613b14..35a52d31b9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -50,6 +50,7 @@ Sanborn Hilland Seth Madison Thomas Stephens Timothy Drews +Torbjörn Einarsson Toshihiro Suzuki Vasanth Polipelli Vignesh Venkatasubramanian diff --git a/lib/media/ttml_text_parser.js b/lib/media/ttml_text_parser.js index 0fc934f943..ab0a58ffc0 100644 --- a/lib/media/ttml_text_parser.js +++ b/lib/media/ttml_text_parser.js @@ -254,11 +254,11 @@ shaka.media.TtmlTextParser.parseCue_ = function( // Disregard empty elements: // TTML allows for empty elements like
. - // 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); diff --git a/test/media/ttml_text_parser_unit.js b/test/media/ttml_text_parser_unit.js index db0a3fcc3c..dad2a3d403 100644 --- a/test/media/ttml_text_parser_unit.js +++ b/test/media/ttml_text_parser_unit.js @@ -38,6 +38,10 @@ describe('TtmlTextParser', function() { verifyHelper([], ''); }); + it('supports div with no cues but whitespace', function() { + verifyHelper([], '
\r\n
'); + }); + it('rejects invalid ttml', function() { errorHelper(shaka.util.Error.Code.INVALID_TTML, ''); errorHelper(shaka.util.Error.Code.INVALID_TTML, '');