mirror of
https://github.com/beetbox/beets.git
synced 2025-12-27 19:12:40 +01:00
properly safe cast unicode as int
This commit is contained in:
parent
d0522d88ef
commit
9fe171c5ce
1 changed files with 4 additions and 2 deletions
|
|
@ -154,10 +154,12 @@ def _safe_cast(out_type, val):
|
|||
return int(val)
|
||||
else:
|
||||
# Process any other type as a string.
|
||||
if not isinstance(val, six.string_types):
|
||||
if isinstance(val, bytes):
|
||||
val = val.decode('utf-8', 'ignore')
|
||||
elif not isinstance(val, six.string_types):
|
||||
val = six.text_type(val)
|
||||
# Get a number from the front of the string.
|
||||
val = re.match(r'[0-9]*', val.strip()).group(0)
|
||||
val = re.match(r'[\+-]?[0-9]*', val.strip()).group(0)
|
||||
if not val:
|
||||
return 0
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue