_sanitize_path now uses a non-unicode regex

This commit is contained in:
Adrian Sampson 2010-08-06 10:01:49 -07:00
parent d1c6448da8
commit 181949d1a3
2 changed files with 13 additions and 3 deletions

View file

@ -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.

View file

@ -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__)