fix(id3v2): prevent crash when no tag frames present
Fix TypeError: Cannot read properties of undefined (reading 'filter') by defaulting missing frame/tag collections to empty arrays/objects. - Add MP3 sample without tags + regression test - Update related TS configs and dependencies/lockfile
This commit is contained in:
@@ -104,7 +104,7 @@ export class ID3v2Parser {
|
||||
await (id3Header.flags.isExtendedHeader ? this.parseExtendedHeader() : this.parseId3Data(id3Header.size));
|
||||
|
||||
// Post process
|
||||
const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType], this.metadata.format.sampleRate);
|
||||
const chapters = ID3v2Parser.mapId3v2Chapters(this.metadata.native[this.headerType]);
|
||||
this.metadata.setFormat('chapters', chapters);
|
||||
}
|
||||
|
||||
@@ -178,10 +178,9 @@ export class ID3v2Parser {
|
||||
* This function expects the `native` tags already to contain parsed `CHAP` and `CTOC` frame values,
|
||||
* as produced by `FrameParser.readData`.
|
||||
*/
|
||||
private static mapId3v2Chapters(
|
||||
id3Tags: ITag[],
|
||||
sampleRate?: number
|
||||
): IChapter[] | undefined {
|
||||
private static mapId3v2Chapters(id3Tags?: ITag[]): IChapter[] | undefined {
|
||||
|
||||
if (!id3Tags) return;
|
||||
|
||||
const chapFrames = id3Tags.filter(t => t.id === 'CHAP') as any[] | undefined;
|
||||
if (!chapFrames?.length) return;
|
||||
|
||||
Binary file not shown.
@@ -24,6 +24,14 @@ describe('Parse MP3 files', () => {
|
||||
|
||||
const mp3SamplePath = path.join(samplePath, 'mp3');
|
||||
|
||||
it('should handle MP3 without any tags', async () => {
|
||||
const filePath = path.join(mp3SamplePath, 'notags.mp3');
|
||||
const {format, native} = await mm.parseFile(filePath, {includeChapters: true});
|
||||
assert.strictEqual(format.container, 'MPEG');
|
||||
assert.strictEqual(format.codec, 'MPEG 2 Layer 3');
|
||||
assert.strictEqual(Object.keys(native).length, 0, 'Should be empty');
|
||||
});
|
||||
|
||||
describe('Test patterns for ISO/MPEG ', () => {
|
||||
|
||||
it.skip('ISO/MPEG 1 Layer 1', async () => {
|
||||
|
||||
Reference in New Issue
Block a user