Skip to content

Commit

Permalink
Merge branch 'hotfix/latin1-apic-frames'
Browse files Browse the repository at this point in the history
  • Loading branch information
benrr101 committed May 8, 2021
2 parents 967a302 + b709116 commit 1677557
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-taglib-sharp",
"description": "Read and write audio/video/picture tags using a similar interface to TagLib#",
"version": "3.3.0",
"version": "3.3.1",
"license": "LGPL-2.1-or-later",
"author": "Ben Russell <[email protected]> (https://github.com/benrr101)",
"repository": "github:benrr101/node-taglib-sharp",
Expand Down
2 changes: 1 addition & 1 deletion src/id3v2/frames/attachmentFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export default class AttachmentFrame extends Frame implements IPicture {
// Picture type $xx
// Description <text string according to encoding> $00 (00)
// Picture data <binary data>
const mimeTypeEndIndex = data.find(ByteVector.getTextDelimiter(StringType.Latin1));
const mimeTypeEndIndex = data.find(ByteVector.getTextDelimiter(StringType.Latin1), 1);
if (mimeTypeEndIndex === -1) {
return;
}
Expand Down
48 changes: 42 additions & 6 deletions test-unit/id3v2/attachmentsFrameTests.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import * as Chai from "chai";
import * as ChaiAsPromised from "chai-as-promised";
import * as TypeMoq from "typemoq";
import FrameConstructorTests from "./frameConstructorTests";
import PropertyTests from "../utilities/propertyTests";
import {Testers} from "../utilities/testers";
import {suite, test} from "mocha-typescript";

import AttachmentFrame from "../../src/id3v2/frames/attachmentFrame";
import FrameConstructorTests from "./frameConstructorTests";
import Id3v2Settings from "../../src/id3v2/id3v2Settings";
import PropertyTests from "../utilities/propertyTests";
import {ByteVector, StringType} from "../../src/byteVector";
import {Frame, FrameClassType} from "../../src/id3v2/frames/frame";
import {Id3v2FrameHeader} from "../../src/id3v2/frames/frameHeader";
import {FrameIdentifier, FrameIdentifiers} from "../../src/id3v2/frameIdentifiers";
import {IPicture, PictureType} from "../../src/iPicture";
import {Testers} from "../utilities/testers";

// Setup chai
Chai.use(ChaiAsPromised);
const assert = Chai.assert;

function getTestFrame() {
Expand Down Expand Up @@ -137,8 +135,46 @@ function getCustomTestFrame(data: ByteVector, desc: string, filename: string, mi
assert.throws(() => { const _ = AttachmentFrame.fromRawData(data, 4); });
}

// NOTE: If you're wondering why we have a test for latin1 vs other encodings, it's b/c the
// mimetype detection looks for a 0 to mark the end of the mimetype. If encoding is Latin1,
// the first byte of the picture is 0, which we want to make sure isn't mistaken for the end
// of the mimetype.

@test
public fromRawData_apicV4_latin1Encoding() {
// Arrange
const testData = ByteVector.fromString("fuxbuxqux", StringType.Latin1);
const header = new Id3v2FrameHeader(FrameIdentifiers.APIC);
header.frameSize = 41;
const data = ByteVector.concatenate(
header.render(4),
StringType.Latin1,
ByteVector.fromString("image/gif", StringType.Latin1),
ByteVector.getTextDelimiter(StringType.Latin1),
PictureType.Artist,
ByteVector.fromString("foobarbaz", StringType.Latin1),
ByteVector.getTextDelimiter(StringType.Latin1),
testData
);

// Act
const frame = AttachmentFrame.fromRawData(data, 4);

// Assert
this.verifyFrame(
frame,
FrameIdentifiers.APIC,
testData,
"foobarbaz",
undefined,
"image/gif",
StringType.Latin1,
PictureType.Artist
);
}

@test
public fromRawData_apicV4() {
public fromRawData_apicV4_nonLatinEncoding() {
// Arrange
const testData = ByteVector.fromString("fuxbuxqux", StringType.Latin1);
const header = new Id3v2FrameHeader(FrameIdentifiers.APIC);
Expand Down

0 comments on commit 1677557

Please sign in to comment.