New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some fixes for non-ASCII chars in MPD uris #1805
Conversation
Codecov Report
@@ Coverage Diff @@
## release-2.2 #1805 +/- ##
==============================================
+ Coverage 80.99% 81% +<.01%
==============================================
Files 83 83
Lines 6647 6649 +2
==============================================
+ Hits 5384 5386 +2
Misses 1263 1263
Continue to review full report at Codecov.
|
@@ -49,6 +49,7 @@ def get_distinct(self, field, query=None): | |||
return self.dummy_get_distinct_result.get(field, set()) | |||
|
|||
def lookup(self, uri): | |||
uri = Ref.track(uri=uri).uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looked like a no-op to me at first, but this actually encodes the URI as bytes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! It's so tempting to just compare two stringy things called uri
but you can't.
@@ -22,6 +22,7 @@ def __init__(self, *args, **kwargs): | |||
self.response = [] | |||
|
|||
def queue_send(self, data): | |||
data = data.decode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data
is one small step away from being sent over the network, so it wouldn't be unnatural to keep it as bytes. If we change this to the following, it should work correctly on both Python 2 and 3:
if isinstance(data, compat.text_type):
data = data.encode('utf-8')
lines = (line for line in data.split(b'\n') if line) # Note the explicit 'b' here
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sounds sensible. Will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but actually, no. This isn't going over the network and don't we want unicode here so that we can just write unicode in the tests?
I've just realised I missed the other URI at https://github.com/mopidy/mopidy/blob/develop/mopidy/mpd/translator.py#L113 |
Related to mopidy#1805.
Related to mopidy#1805.
Fixes #1759
Most of this comes from Track
uri
s beingbytes
but falling over when formatted withunicode
strings for output / logging. And then I went a bit mad sprinkling non-ASCII throughout the tests.