mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
MediaFile: detect missing numbers (fix #901)
This commit is contained in:
parent
09b0e1c75d
commit
bf553eae34
3 changed files with 12 additions and 5 deletions
|
|
@ -154,11 +154,12 @@ def _safe_cast(out_type, val):
|
|||
else:
|
||||
if not isinstance(val, basestring):
|
||||
val = unicode(val)
|
||||
val = re.match(r'[\+-]?[0-9\.]*', val.strip()).group(0)
|
||||
if not val:
|
||||
return 0.0
|
||||
else:
|
||||
return float(val)
|
||||
match = re.match(r'[\+-]?[0-9\.]+', val.strip())
|
||||
if match:
|
||||
val = match.group(0)
|
||||
if val:
|
||||
return float(val)
|
||||
return 0.0
|
||||
|
||||
else:
|
||||
return val
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ Little improvements and fixes:
|
|||
* :doc:`/plugins/convert`: A new ``--pretend`` option lets you preview the
|
||||
commands the plugin will execute without actually taking any action. Thanks
|
||||
to Dietrich Daroch.
|
||||
* Fix a crash when a float-valued tag field only contained a ``+`` or ``-``
|
||||
character.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -107,6 +107,10 @@ class InvalidValueToleranceTest(unittest.TestCase):
|
|||
self.assertTrue(isinstance(us, unicode))
|
||||
self.assertTrue(us.startswith(u'caf'))
|
||||
|
||||
def test_safe_cast_float_with_no_numbers(self):
|
||||
v = _sc(float, '+')
|
||||
self.assertEqual(v, 0.0)
|
||||
|
||||
|
||||
class SafetyTest(unittest.TestCase, TestHelper):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue