diff --git a/beets/library.py b/beets/library.py index 99397013b..5ae0182e3 100644 --- a/beets/library.py +++ b/beets/library.py @@ -85,8 +85,14 @@ class PathQuery(dbcore.FieldQuery): colon = query_part.find(':') if colon != -1: query_part = query_part[:colon] - return (os.sep in query_part and - os.path.exists(syspath(normpath(query_part)))) + + # Test both `sep` and `altsep` (i.e., both slash and backslash on + # Windows). + return ( + (os.sep in query_part or + (os.altsep and os.altsep in query_part)) and + os.path.exists(syspath(normpath(query_part))) + ) def match(self, item): path = item.path if self.case_sensitive else item.path.lower() diff --git a/docs/changelog.rst b/docs/changelog.rst index b0aa1e777..dd4424332 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,11 @@ Changelog Changelog goes here! +Some fixes for Windows: + +* Queries are now detected as paths when they contain backslashes (in + addition to forward slashes). This only applies on Windows. + 1.3.18 (May 31, 2016) --------------------- diff --git a/test/test_query.py b/test/test_query.py index b9c87ff87..79bc11743 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -569,7 +569,10 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin): @patch('beets.library.os') def test_path_sep_detection(self, mock_os): mock_os.sep = '/' + mock_os.altsep = None + mock_os.path.exists = lambda p: True is_path = beets.library.PathQuery.is_path_query + self.assertTrue(is_path('/foo/bar')) self.assertTrue(is_path('foo/bar')) self.assertTrue(is_path('foo/'))