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

Fixed loading of playlists that contain quoted attribute values #139

Merged
merged 1 commit into from
Dec 23, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/loader/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class PlaylistLoader {

Object.assign(level, level.attrs.decimalResolution('RESOLUTION'));
level.bitrate = level.attrs.decimalInteger('BANDWIDTH');
level.name = level.attrs.quotedString('NAME');
level.name = level.attrs.NAME;

var codecs = level.attrs.quotedString('CODECS');
var codecs = level.attrs.CODECS;
if(codecs) {
codecs = codecs.split(',');
for (let i = 0; i < codecs.length; i++) {
Expand Down Expand Up @@ -174,7 +174,7 @@ class PlaylistLoader {
var decryptparams = result[1];
var keyAttrs = new AttrList(decryptparams);
var decryptmethod = keyAttrs.enumeratedString('METHOD'),
decrypturi = keyAttrs.quotedString('URI'),
decrypturi = keyAttrs.URI,
decryptiv = keyAttrs.hexadecimalInteger('IV');
if (decryptmethod) {
levelkey = { method: null, key: null, iv: null, uri: null };
Expand Down
11 changes: 5 additions & 6 deletions src/utils/attr-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class AttrList {
return parseFloat(this[attrName]);
}

quotedString(attrName) {
const val = this[attrName];
return val ? val.slice(1, -1) : undefined;
}

enumeratedString(attrName) {
return this[attrName];
}
Expand All @@ -69,7 +64,11 @@ class AttrList {
const re = /(.+?)=((?:\".*?\")|.*?)(?:,|$)/g;
var match, attrs = {};
while ((match = re.exec(input)) !== null) {
attrs[match[1]] = match[2];
var value = match[2];
if (value.startsWith('"') && value.endsWith('"')) {
value = value.slice(1, -1);
}
attrs[match[1]] = value;
}
return attrs;
}
Expand Down
17 changes: 11 additions & 6 deletions tests/unit/utils/attr-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,32 @@ describe('AttrList', () => {
it('parses valid decimalInteger attribute', () => {
assert.strictEqual(new AttrList('INT=42').decimalInteger('INT'), 42);
assert.strictEqual(new AttrList('INT=0').decimalInteger('INT'), 0);
assert.strictEqual(new AttrList('INT="42"').decimalInteger('INT'), 42);
});
it('parses valid hexadecimalInteger attribute', () => {
assert.strictEqual(new AttrList('HEX=0x42').hexadecimalIntegerAsNumber('HEX'), 0x42);
assert.strictEqual(new AttrList('HEX=0X42').hexadecimalIntegerAsNumber('HEX'), 0x42);
assert.strictEqual(new AttrList('HEX=0x0').hexadecimalIntegerAsNumber('HEX'), 0);
assert.strictEqual(new AttrList('HEX="0x42"').hexadecimalIntegerAsNumber('HEX'), 0x42);
});
it('parses valid decimalFloatingPoint attribute', () => {
assert.strictEqual(new AttrList('FLOAT=0.42').decimalFloatingPoint('FLOAT'), 0.42);
assert.strictEqual(new AttrList('FLOAT=-0.42').decimalFloatingPoint('FLOAT'), -0.42);
assert.strictEqual(new AttrList('FLOAT=0').decimalFloatingPoint('FLOAT'), 0);
assert.strictEqual(new AttrList('FLOAT="0.42"').decimalFloatingPoint('FLOAT'), 0.42);
});
it('parses valid quotedString attribute', () => {
assert.strictEqual(new AttrList('STRING="hi"').quotedString('STRING'), 'hi');
assert.strictEqual(new AttrList('STRING=""').quotedString('STRING'), '');
assert.strictEqual(new AttrList('STRING="hi"').STRING, 'hi');
assert.strictEqual(new AttrList('STRING=""').STRING, '');
});
it('parses exotic quotedString attribute', () => {
const list = new AttrList('STRING="hi,ENUM=OK,RES=4x2"');
assert.strictEqual(list.quotedString('STRING'), 'hi,ENUM=OK,RES=4x2');
assert.strictEqual(list.STRING, 'hi,ENUM=OK,RES=4x2');
assert.strictEqual(Object.keys(list).length, 1);
});
it('parses valid enumeratedString attribute', () => {
assert.strictEqual(new AttrList('ENUM=OK').enumeratedString('ENUM'), 'OK');
assert.strictEqual(new AttrList('ENUM="OK"').enumeratedString('ENUM'), 'OK');
});
it('parses exotic enumeratedString attribute', () => {
assert.strictEqual(new AttrList('ENUM=1').enumeratedString('ENUM'), '1');
Expand All @@ -54,6 +58,7 @@ describe('AttrList', () => {
it('parses valid decimalResolution attribute', () => {
assert(deepStrictEqual(new AttrList('RES=400x200').decimalResolution('RES'), { width:400, height:200 }));
assert(deepStrictEqual(new AttrList('RES=0x0').decimalResolution('RES'), { width:0, height:0 }));
assert(deepStrictEqual(new AttrList('RES="400x200"').decimalResolution('RES'), { width:400, height:200 }));
});
it('handles invalid decimalResolution attribute', () => {
assert(deepStrictEqual(new AttrList('RES=400x-200').decimalResolution('RES'), undefined));
Expand All @@ -70,7 +75,7 @@ describe('AttrList', () => {
assert.strictEqual(list.decimalInteger('INT'), 42);
assert.strictEqual(list.hexadecimalIntegerAsNumber('HEX'), 0x42);
assert.strictEqual(list.decimalFloatingPoint('FLOAT'), 0.42);
assert.strictEqual(list.quotedString('STRING'), 'hi');
assert.strictEqual(list.STRING, 'hi');
assert.strictEqual(list.enumeratedString('ENUM'), 'OK');
assert(deepStrictEqual(list.decimalResolution('RES'), { width:4, height:2 }));
assert.strictEqual(Object.keys(list).length, 6);
Expand All @@ -81,7 +86,7 @@ describe('AttrList', () => {
assert(isNaN(list.decimalInteger('INT')));
assert(isNaN(list.hexadecimalIntegerAsNumber('HEX')));
assert(isNaN(list.decimalFloatingPoint('FLOAT')));
assert.strictEqual(list.quotedString('STRING'), undefined);
assert.strictEqual(list.STRING, undefined);
assert.strictEqual(list.enumeratedString('ENUM'), undefined);
assert.strictEqual(list.decimalResolution('RES'), undefined);
assert.strictEqual(Object.keys(list).length, 0);
Expand All @@ -92,7 +97,7 @@ describe('AttrList', () => {
assert.strictEqual(list.decimalInteger('INT-VALUE'), 42);
assert.strictEqual(list.hexadecimalIntegerAsNumber('H-E-X'), 0x42);
assert.strictEqual(list.decimalFloatingPoint('-FLOAT'), 0.42);
assert.strictEqual(list.quotedString('STRING-'), 'hi');
assert.strictEqual(list['STRING-'], 'hi');
assert.strictEqual(list.enumeratedString('ENUM'), 'OK');
assert.strictEqual(Object.keys(list).length, 5);
});
Expand Down