Skip to content

Commit 55e9543

Browse files
committed
fix(mb): Accept every UUID version as valid MBID
Some releases have v3 UUIDs from the NGS migration.
1 parent d70a5ef commit 55e9543

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

musicbrainz/extract_mbid.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { assertEquals } from 'std/assert/assert_equals.ts';
2+
import { assertThrows } from 'std/assert/assert_throws.ts';
3+
import { describe, it } from '@std/testing/bdd';
4+
import { extractMBID } from './extract_mbid.ts';
5+
6+
describe('extractMBID', () => {
7+
it('accepts a v4 UUID', () => {
8+
const v4uuid = 'e5a77768-ff64-46f2-a13e-9d368b413cff';
9+
assertEquals(extractMBID(v4uuid), v4uuid);
10+
});
11+
12+
it('accepts a v3 UUID', () => {
13+
const v3uuid = '9706e7fa-4ed1-3b40-b638-45a21ff634f5';
14+
assertEquals(extractMBID(v3uuid), v3uuid);
15+
});
16+
17+
it('accepts a MusicBrainz entity link', () => {
18+
assertEquals(
19+
extractMBID('https://musicbrainz.org/recording/e5a77768-ff64-46f2-a13e-9d368b413cff'),
20+
'e5a77768-ff64-46f2-a13e-9d368b413cff',
21+
);
22+
});
23+
24+
it('accepts only MusicBrainz entity links with the expected type', () => {
25+
assertEquals(
26+
extractMBID('https://beta.musicbrainz.org/release/da14004d-f6af-4dd7-aab7-033bef53e805', ['release']),
27+
'da14004d-f6af-4dd7-aab7-033bef53e805',
28+
);
29+
assertThrows(
30+
() => extractMBID('https://musicbrainz.org/recording/e5a77768-ff64-46f2-a13e-9d368b413cff', ['release']),
31+
);
32+
});
33+
34+
it('rejects any other text', () => {
35+
assertThrows(() => extractMBID('test'));
36+
});
37+
});

musicbrainz/extract_mbid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type EntityType, entityTypes } from '@kellnerd/musicbrainz/data/entity';
22
import { assert } from 'std/assert/assert.ts';
3-
import { validate } from '@std/uuid/v4';
3+
import { validate } from '@std/uuid';
44

55
const MBID_LENGTH = 36;
66

0 commit comments

Comments
 (0)