From 4359845a015dd86d8b1735dd11d7ee548ebb5230 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 19 Jan 2011 13:17:54 -0800 Subject: [PATCH] prohibit trailing spaces in Windows filenames --- NEWS | 3 ++- beets/library.py | 2 +- test/test_db.py | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e61657c5b..3bf2fb560 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/beets/library.py b/beets/library.py index 140441ca6..bbc738628 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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 diff --git a/test/test_db.py b/test/test_db.py index 1d857b8d5..fa81fc8f6 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -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