fixed safetifying of destination paths

--HG--
extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%40220
This commit is contained in:
adrian.sampson 2009-04-15 05:48:40 +00:00
parent e8962f99c6
commit debebc616c
2 changed files with 14 additions and 1 deletions

View file

@ -297,7 +297,7 @@ class Item(object):
# replace / and leading . with _
if isinstance(value, basestring):
value.replace(os.sep, '_')
re.sub(r'[' + os.sep + r']|^\.', '_', value)
value = re.sub(r'[\\/:]|^\.', '_', value)
elif key in ('track', 'tracktotal', 'disc', 'disctotal'):
# pad with zeros
value = '%02i' % value

View file

@ -151,6 +151,19 @@ class AddTest(unittest.TestCase):
self.lib.add(os.path.join('rsrc', 'full.mp3'), copy=True)
self.assertTrue(os.path.isfile(os.path.join(self.dir, 'item')))
class DestinationTest(unittest.TestCase):
def setUp(self):
self.lib = beets.library.Library(':memory:')
self.i = beets.library.Item.from_path(join('rsrc', 'full.mp3'))
self.i.library = self.lib
def test_destination_escapes_slashes(self):
self.i.album = 'one/two'
dest = self.i.destination()
self.assertTrue('one' in dest)
self.assertTrue('two' in dest)
self.assertFalse('one/two' in dest)
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)