prohibit trailing spaces in Windows filenames

This commit is contained in:
Adrian Sampson 2011-01-19 13:17:54 -08:00
parent 5904852e4b
commit 4359845a01
3 changed files with 7 additions and 2 deletions

3
NEWS
View file

@ -20,7 +20,8 @@
completely wrong association of track names to files. The order
applied was always just alphabetical by filename, which is frequently
but not always what you want.
* We now use Windows' "long filename" support.
* We now use Windows' "long filename" support. Filenames on Windows now
also never end in spaces.
* Fix crash in lastid when the artist name is not available.
* Fixed a spurious crash when LANG or a related environment variable is
set to an invalid value (such as 'UTF-8' on some installations of Mac

View file

@ -209,7 +209,7 @@ CHAR_REPLACE = [
(re.compile(r'[\\/\?]|^\.'), '_'),
(re.compile(r':'), '-'),
]
CHAR_REPLACE_WINDOWS = re.compile('["\*<>\|]|^\.|\.$'), '_'
CHAR_REPLACE_WINDOWS = re.compile('["\*<>\|]|^\.|\.$| +$'), '_'
def _sanitize_path(path, pathmod=None):
"""Takes a path and makes sure that it is legal. Returns a new path.
Only works with fragments; won't work reliably on Windows when a

View file

@ -283,6 +283,10 @@ class DestinationTest(unittest.TestCase):
outpath = beets.library._syspath(path, posixpath)
self.assertEqual(path, outpath)
def test_sanitize_windows_replaces_trailing_space(self):
p = beets.library._sanitize_path('one/two /three', ntpath)
self.assertFalse(' ' in p)
class MigrationTest(unittest.TestCase):
"""Tests the ability to change the database schema between