From a06a421ce87ccf5f04573727f7f72f029731b254 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Tue, 8 Sep 2015 16:04:26 +0200 Subject: [PATCH 1/4] Bugfix for cas insensitive searches for a file path. Fixes #1587. --- beets/library.py | 8 ++------ docs/changelog.rst | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/beets/library.py b/beets/library.py index 85c6e1b40..b4da8ad50 100644 --- a/beets/library.py +++ b/beets/library.py @@ -66,10 +66,6 @@ class PathQuery(dbcore.FieldQuery): case_sensitive = platform.system() != 'Windows' self.case_sensitive = case_sensitive - # Use a normalized-case pattern for case-insensitive matches. - if not case_sensitive: - pattern = pattern.lower() - # Match the path as a single file. self.file_path = util.bytestring_path(util.normpath(pattern)) # As a directory (prefix). @@ -102,8 +98,8 @@ class PathQuery(dbcore.FieldQuery): escape = lambda m: self.escape_char + m.group(0) dir_pattern = self.escape_re.sub(escape, self.dir_path) dir_blob = buffer(dir_pattern + b'%') - return '({0} = ?) || ({0} LIKE ? ESCAPE ?)'.format(self.field), \ - (file_blob, dir_blob, self.escape_char) + return '(lower({0}) = lower(?)) || ({0} LIKE ? ESCAPE ?)'.format( + self.field), (file_blob, dir_blob, self.escape_char) # Library-specific field types. diff --git a/docs/changelog.rst b/docs/changelog.rst index bb090a20e..bee5fe373 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -43,6 +43,8 @@ Fixes: written to files. Thanks to :user:`jdetrey`. :bug:`1303` :bug:`1589` * :doc:`/plugins/replaygain`: Avoid a crash when the PyAudioTools backend encounters an error. :bug:`1592` +* Case insensitive searches might have returned nothing because of a wrong + SQL query. 1.3.14 (August 2, 2015) From f79d1ab205b10743282444e0d7002767ce7f8222 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Fri, 11 Sep 2015 19:16:00 +0200 Subject: [PATCH 2/4] Changed the WHERE clause of a PathQuery to use LIKE instead of lower() --- beets/library.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/beets/library.py b/beets/library.py index b4da8ad50..945806b8b 100644 --- a/beets/library.py +++ b/beets/library.py @@ -66,6 +66,10 @@ class PathQuery(dbcore.FieldQuery): case_sensitive = platform.system() != 'Windows' self.case_sensitive = case_sensitive + # Use a normalized-case pattern for case-insensitive matches. + if not case_sensitive: + pattern = pattern.lower() + # Match the path as a single file. self.file_path = util.bytestring_path(util.normpath(pattern)) # As a directory (prefix). @@ -88,9 +92,8 @@ class PathQuery(dbcore.FieldQuery): return (path == self.file_path) or path.startswith(self.dir_path) def col_clause(self): - file_blob = buffer(self.file_path) - if self.case_sensitive: + file_blob = buffer(self.file_path) dir_blob = buffer(self.dir_path) return '({0} = ?) || (substr({0}, 1, ?) = ?)'.format(self.field), \ (file_blob, len(dir_blob), dir_blob) @@ -98,8 +101,11 @@ class PathQuery(dbcore.FieldQuery): escape = lambda m: self.escape_char + m.group(0) dir_pattern = self.escape_re.sub(escape, self.dir_path) dir_blob = buffer(dir_pattern + b'%') - return '(lower({0}) = lower(?)) || ({0} LIKE ? ESCAPE ?)'.format( - self.field), (file_blob, dir_blob, self.escape_char) + file_pattern = self.escape_re.sub(escape, self.file_path) + file_blob = buffer(file_pattern + b'%') + return '({0} LIKE ? ESCAPE ?) || ({0} LIKE ? ESCAPE ?)'.format( + self.field), (file_blob, self.escape_char, dir_blob, + self.escape_char) # Library-specific field types. From 0e0941c778e490538b8fc61c4066ce1999bfd598 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Fri, 11 Sep 2015 20:33:02 +0200 Subject: [PATCH 3/4] Little changes for the changelog. --- docs/changelog.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 020e39379..9627fb1bb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -45,8 +45,8 @@ Fixes: written to files. Thanks to :user:`jdetrey`. :bug:`1303` :bug:`1589` * :doc:`/plugins/replaygain`: Avoid a crash when the PyAudioTools backend encounters an error. :bug:`1592` -* Case insensitive searches might have returned nothing because of a wrong - SQL query. +* Case-insensitive path queries might have returned nothing because of a + wrong SQL query. 1.3.14 (August 2, 2015) From ce022a64f6fa9b6d4e90442547566b64f99e2359 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Sat, 12 Sep 2015 20:44:56 +0200 Subject: [PATCH 4/4] Files should be matched exactly so the search for a.mp3 doesn't find a.mp3.foo. --- beets/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/library.py b/beets/library.py index 945806b8b..10cddc69d 100644 --- a/beets/library.py +++ b/beets/library.py @@ -102,7 +102,7 @@ class PathQuery(dbcore.FieldQuery): dir_pattern = self.escape_re.sub(escape, self.dir_path) dir_blob = buffer(dir_pattern + b'%') file_pattern = self.escape_re.sub(escape, self.file_path) - file_blob = buffer(file_pattern + b'%') + file_blob = buffer(file_pattern) return '({0} LIKE ? ESCAPE ?) || ({0} LIKE ? ESCAPE ?)'.format( self.field), (file_blob, self.escape_char, dir_blob, self.escape_char)