fix broken matching of path format queries (#405)

A bug in the shlex module with Unicode strings made these queries unparseable
and thus match every track.
This commit is contained in:
Adrian Sampson 2012-06-23 17:18:28 -07:00
parent 9efdf93dd6
commit 073ee14e56
3 changed files with 20 additions and 2 deletions

View file

@ -595,7 +595,14 @@ class CollectionQuery(Query):
"""Creates a query based on a single string. The string is split
into query parts using shell-style syntax.
"""
return cls.from_strings(shlex.split(query))
# A bug in Python < 2.7.3 prevents correct shlex splitting of
# Unicode strings.
# http://bugs.python.org/issue6988
if isinstance(query, unicode):
pass
query = query.encode('utf8')
parts = [s.decode('utf8') for s in shlex.split(query)]
return cls.from_strings(parts)
class AnySubstringQuery(CollectionQuery):
"""A query that matches a substring in any of a list of metadata

View file

@ -46,7 +46,9 @@ Changelog
* When previewing changes during import, differences in track duration are now
shown as "2:50 vs. 3:10" rather than separated with ``->`` like track numbers.
This should clarify that beets isn't doing anything to modify lengths.
* :doc:`/plugins/chroma`: Fix tracking with ambiguous Acoustids. Some Acoustids
* Fix a problem with query-based path format matching where a field-qualified
pattern, like ``albumtype_soundtrack``, would match everything.
* :doc:`/plugins/chroma`: Fix matching with ambiguous Acoustids. Some Acoustids
are identified with multiple recordings; beets now considers any associated
recording a valid match. This should reduce some cases of errant track
reordering when using chroma.

View file

@ -421,6 +421,15 @@ class CountTest(unittest.TestCase):
self.assertEqual(songs, 0)
self.assertEqual(totaltime, 0.0)
class StringParseTest(unittest.TestCase):
def test_single_field_query(self):
q = beets.library.AndQuery.from_string(u'albumtype:soundtrack')
self.assertEqual(len(q.subqueries), 1)
subq = q.subqueries[0]
self.assertTrue(isinstance(subq, beets.library.SubstringQuery))
self.assertEqual(subq.field, 'albumtype')
self.assertEqual(subq.pattern, 'soundtrack')
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)