Skip to content

Commit 1a1fc94

Browse files
authored
Merge pull request #137 from slipszi/do-not-unsynchronize-twice
Do not unsynchronize frames twice.
2 parents 75c5c94 + 5acda04 commit 1a1fc94

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/ID3v2FrameReader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class ID3v2FrameReader {
249249
}
250250

251251
var unsyncData;
252-
if (flags && flags.format.unsynchronisation) {
252+
if (flags && flags.format.unsynchronisation && !id3header.flags.unsynchronisation) {
253253
frameData = this.getUnsyncFileReader(frameData, frameDataOffset, frameSize);
254254
frameDataOffset = 0;
255255
frameSize = frameData.getSize();

src/__tests__/ID3v2TagReader-test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,41 @@ describe("ID3v2TagReader", function() {
284284
expect(tags.tags.picture.data).toEqual([0x01, 0x02, 0xff, 0x03, 0x04, 0x05]);
285285
});
286286
});
287+
288+
it("doesn't unsynchronise frames twice", function() {
289+
var id3FileContents =
290+
new ID3v2TagContents(4, 3)
291+
.setFlags({
292+
unsynchronisation: true
293+
})
294+
.addFrame("TIT2", [].concat(
295+
[0x00], // encoding
296+
bin("The title"), [0x00]
297+
))
298+
.addFrame("APIC", [].concat(
299+
[0x00], // text encoding
300+
bin("image/jpeg"), [0x00],
301+
[0x03], // picture type - cover front
302+
bin("front cover image"), [0x00],
303+
[0x01, 0x02, 0xff, 0x00, 0x00, 0x03, 0x04, 0x05] // image data
304+
), {
305+
format: {
306+
unsynchronisation: true
307+
}
308+
});
309+
mediaFileReader = new ArrayFileReader(id3FileContents.toArray());
310+
tagReader = new ID3v2TagReader(mediaFileReader);
311+
312+
return new Promise(function(resolve, reject) {
313+
tagReader.read({
314+
onSuccess: resolve,
315+
onFailure: reject
316+
});
317+
jest.runAllTimers();
318+
}).then(function(tags) {
319+
expect(tags.tags.picture.data).toEqual([0x01, 0x02, 0xff, 0x00, 0x03, 0x04, 0x05]);
320+
});
321+
});
287322
});
288323

289324
it("should process frames with no content", function() {

0 commit comments

Comments
 (0)