From 0d4698a8af17a72b0953419e985346e30b798c55 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 31 Jan 2014 13:14:45 -0800 Subject: [PATCH] fix #517: BytesQuery accepts unicode strings --- beets/dbcore/query.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index 32062a1e9..74f6cb903 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -151,7 +151,11 @@ class BytesQuery(MatchQuery): # Use a buffer representation of the pattern for SQLite # matching. This instructs SQLite to treat the blob as binary # rather than encoded Unicode. - if isinstance(self.pattern, bytes): + if isinstance(self.pattern, basestring): + # Implicitly coerce Unicode strings to their bytes + # equivalents. + if isinstance(self.pattern, unicode): + self.pattern = self.pattern.encode('utf8') self.buf_pattern = buffer(self.pattern) elif isinstance(self.pattern, buffer): self.buf_pattern = self.pattern