diff --git a/beets/library.py b/beets/library.py index b892f406b..3adea78e8 100644 --- a/beets/library.py +++ b/beets/library.py @@ -178,10 +178,10 @@ def _bytestring_path(path): # Note: POSIX actually supports \ and : -- I just think they're # a pain. And ? has caused problems for some. CHAR_REPLACE = [ - (re.compile(r'[\\/\?]|^\.'), u'_'), - (re.compile(r':'), u'-'), + (re.compile(r'[\\/\?]|^\.'), '_'), + (re.compile(r':'), '-'), ] -CHAR_REPLACE_WINDOWS = re.compile('["\*<>\|]|^\.|\.$'), u'_u' +CHAR_REPLACE_WINDOWS = re.compile('["\*<>\|]|^\.|\.$'), '_' def _sanitize_path(path, plat=None): """Takes a path and makes sure that it is legal for the specified platform (as returned by platform.system()). Returns a new path. diff --git a/test/test_db.py b/test/test_db.py index 134cf6dfd..c81b1c15a 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -465,6 +465,16 @@ class PathStringTest(unittest.TestCase): alb = self.lib.get_album(self.i) self.assertEqual(path, alb.artpath) + def test_sanitize_path_with_special_chars(self): + path = 'b\xe1r?' + new_path = beets.library._sanitize_path(path) + self.assert_(new_path.startswith('b\xe1r')) + + def test_sanitize_path_returns_bytestring(self): + path = 'b\xe1r?' + new_path = beets.library._sanitize_path(path) + self.assert_(isinstance(new_path, str)) + def suite(): return unittest.TestLoader().loadTestsFromName(__name__)