From d71737114a301fe6f13d2c2ad28fcadd15527ac3 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 28 Feb 2013 10:00:26 -0800 Subject: [PATCH] format None values as the empty string Fix due to @pscn. Includes test. Closes #108. --- beets/library.py | 2 ++ docs/changelog.rst | 2 ++ test/test_db.py | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/beets/library.py b/beets/library.py index dd2a1ee7f..f07ea7a53 100644 --- a/beets/library.py +++ b/beets/library.py @@ -218,6 +218,8 @@ def format_for_path(value, key=None, pathmod=None): elif key == 'samplerate': # Sample rate formatted as kHz. value = u'%ikHz' % ((value or 0) // 1000) + elif value is None: + value = u'' else: value = unicode(value) diff --git a/docs/changelog.rst b/docs/changelog.rst index 316814836..26e45029b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -24,6 +24,8 @@ Other stuff: * When the importer encounters an error (insufficient permissions, for example) when walking a directory tree, it now logs an error instead of crashing. +* In path formats, null database values now expand to the empty string instead + of the string "None". * Add "System Volume Information" (an internal directory found on some Windows filesystems) to the default ignore list. * Fix a crash when ReplayGain values were set to null. diff --git a/test/test_db.py b/test/test_db.py index d4dd30092..4ee6ea419 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -362,6 +362,10 @@ class DestinationTest(unittest.TestCase): val = beets.library.format_for_path(12345, 'samplerate', posixpath) self.assertEqual(val, u'12kHz') + def test_component_sanitize_none(self): + val = beets.library.format_for_path(None, 'foo', posixpath) + self.assertEqual(val, u'') + def test_artist_falls_back_to_albumartist(self): self.i.artist = '' self.i.albumartist = 'something'