Fix #267: Do not crash when tag contains multiple uuids with a / separator
This commit is contained in:
parent
a16bd2a409
commit
7c47348855
|
@ -91,10 +91,23 @@ def convert_track_number(v):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class FirstUUIDField(forms.UUIDField):
|
||||||
|
def to_python(self, value):
|
||||||
|
try:
|
||||||
|
# sometimes, Picard leaves to uuids in the field, separated
|
||||||
|
# by a slash
|
||||||
|
value = value.split('/')[0]
|
||||||
|
except (AttributeError, IndexError, TypeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return super().to_python(value)
|
||||||
|
|
||||||
|
|
||||||
VALIDATION = {
|
VALIDATION = {
|
||||||
'musicbrainz_artistid': forms.UUIDField(),
|
'musicbrainz_artistid': FirstUUIDField(),
|
||||||
'musicbrainz_albumid': forms.UUIDField(),
|
'musicbrainz_albumid': FirstUUIDField(),
|
||||||
'musicbrainz_recordingid': forms.UUIDField(),
|
'musicbrainz_recordingid': FirstUUIDField(),
|
||||||
}
|
}
|
||||||
|
|
||||||
CONF = {
|
CONF = {
|
||||||
|
|
|
@ -95,3 +95,17 @@ def test_can_get_metadata_from_flac_file_not_crash_if_empty():
|
||||||
|
|
||||||
with pytest.raises(metadata.TagNotFound):
|
with pytest.raises(metadata.TagNotFound):
|
||||||
data.get('test')
|
data.get('test')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('field_name', [
|
||||||
|
'musicbrainz_artistid',
|
||||||
|
'musicbrainz_albumid',
|
||||||
|
'musicbrainz_recordingid',
|
||||||
|
])
|
||||||
|
def test_mbid_clean_keeps_only_first(field_name):
|
||||||
|
u1 = str(uuid.uuid4())
|
||||||
|
u2 = str(uuid.uuid4())
|
||||||
|
field = metadata.VALIDATION[field_name]
|
||||||
|
result = field.to_python('/'.join([u1, u2]))
|
||||||
|
|
||||||
|
assert str(result) == u1
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Do not crash when tag contains multiple uuids with a / separator (#267)
|
Loading…
Reference in New Issue