Skip to content

Commit f0ce5c4

Browse files
authored
fix: handle correctly semicolon on the end of the fmtp line (#23)
1 parent 9697290 commit f0ce5c4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/lines/fmtp-line.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ describe('parseFmtpParams', () => {
2727
expect(Object.fromEntries(fmtpParams)).toStrictEqual({ '0-5': undefined }); // firefox RED
2828
fmtpParams = parseFmtpParams('a=fmtp:100 0-15,66,70');
2929
expect(Object.fromEntries(fmtpParams)).toStrictEqual({ '0-15,66,70': undefined }); // telephone event
30+
fmtpParams = parseFmtpParams('a=fmtp:45 profile=0;level-idx=19;tier=0;');
31+
expect(Object.fromEntries(fmtpParams)).toStrictEqual({
32+
'level-idx': '19',
33+
profile: '0',
34+
tier: '0',
35+
}); // semicolon at the end case
3036
});
3137
it('exceptional case', async () => {
3238
expect.hasAssertions();

src/lines/fmtp-line.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ export function parseFmtpParams(fmtpParams: string) {
3737
return fmtpObj;
3838
}
3939

40+
// Trailing semicolons are not technically allowed, but we've seen some occurrences and don't want to choke on them, so strip them here
41+
// eslint-disable-next-line no-param-reassign
42+
fmtpParams = fmtpParams.replace(/;$/, '');
43+
4044
fmtpParams.split(';').forEach((param) => {
4145
const paramArr = param && param.split('=');
46+
4247
if (paramArr.length !== 2 || !paramArr[0] || !paramArr[1]) {
4348
throw new Error(`Fmtp params is invalid with ${fmtpParams}`);
4449
}

0 commit comments

Comments
 (0)