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 case where TTML data is an empty string #1960

Merged
merged 4 commits into from
Sep 11, 2019
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
6 changes: 6 additions & 0 deletions lib/text/ttml_text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ shaka.text.TtmlTextParser = class {
const parser = new DOMParser();
let xml = null;

// dont try to parse empty string as
// DOMParser will not throw error but return an errored xml
if (str == '') {
return ret;
}

try {
xml = parser.parseFromString(str, 'text/xml');
} catch (exception) {
Expand Down
7 changes: 6 additions & 1 deletion test/text/ttml_text_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe('TtmlTextParser', () => {
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('supports empty text string', () => {
verifyHelper([],
'',
{periodStart: 0, segmentStart: 0, segmentEnd: 0});
});

it('supports div with no cues but whitespace', () => {
verifyHelper(
[],
Expand Down Expand Up @@ -84,7 +90,6 @@ describe('TtmlTextParser', () => {

it('rejects invalid ttml', () => {
errorHelper(shaka.util.Error.Code.INVALID_XML, '<test></test>');
errorHelper(shaka.util.Error.Code.INVALID_XML, '');
});

it('rejects invalid time format', () => {
Expand Down