You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
punycode codec ignores the error handler argument #56472
b'abc\xff'.decode('punycode', 'ignore') raises the same error than b'abc\xff'.decode('punycode', 'replace') or b'abc\xff'.decode('punycode'): it uses the strict error handler, and simply ignores the error handler.
punycodec, as idna, should raise an exception if the error handler is different than strict.
raise an error if errors="replace": only accept strict and ignore
use errors to encode/decode to/from ASCII
add unit tests
I don't think that the change should be documented, because punycode has no section in Doc/library/codecs.rst, and I hope that nobody uses something different than strict :-)
b'abc\xff-'.decode('punycode', 'ignore') and b'abc\xff-'.decode('punycode', 'replace') raise a UnicodeDecodeError: the error handler is just useless (ignored) here.
With my patch, b'abc\xff-'.decode('punycode', 'ignore') gives 'abc'. (If I change the code to accept replace) b'abc\xff-'.decode('punycode', 'replace') gives also 'abc', but 'replace' doesn't work correctly in the part after "-" contain illegal byte sequences.
For example, b'a\xff-\xffb\xffga\xff'.decode("punycode", "replace") gives 'a�', whereas I would expect 'a�é' or 'aé�'. b'a-bga\xff'.decode("punycode", "replace") gives 'aé' as b'a-bga'.decode("punycode", "replace"), whereas I would expect 'aé�' or something like that.
What's the point of disallowing the replace error handler?
It's just that I'm unable to patch punycode decoder to support the replace handler. Do you want to "implement" it?
That's a slightly incompatible change, isn't it?
I don't think so because I consider that the punycode decoder never supported error handlers (other than strict) in Python 3.
What do you think?
loewis commented on Jun 21, 2011
loewismannequin
Mannequin
More actions
Oh, I forgot to give a little bit more details.
b'abc\xff-'.decode('punycode', 'ignore') and
b'abc\xff-'.decode('punycode', 'replace') raise a UnicodeDecodeError:
the error handler is just useless (ignored) here.
That's not my point:
b"foo".decode("punycode","replace")
currently succeeds, but raises an UnicodeError under the patch.
Activity
vstinner commentedon Jun 4, 2011
b'abc\xff'.decode('punycode', 'ignore') raises the same error than b'abc\xff'.decode('punycode', 'replace') or b'abc\xff'.decode('punycode'): it uses the strict error handler, and simply ignores the error handler.
punycodec, as idna, should raise an exception if the error handler is different than strict.
vstinner commentedon Jun 4, 2011
base64_codec.py uses an assertion to check the error handler: it should use an if+raise (assertions are ignored in optimized mode, python -O).
vstinner commentedon Jun 15, 2011
punycode_errors.patch:
I don't think that the change should be documented, because punycode has no section in Doc/library/codecs.rst, and I hope that nobody uses something different than strict :-)
vstinner commentedon Jun 17, 2011
@martin: Can you review my patch?
loewis commentedon Jun 21, 2011
What's the point of disallowing the replace error handler? That's a slightly incompatible change, isn't it?
vstinner commentedon Jun 21, 2011
Oh, I forgot to give a little bit more details.
b'abc\xff-'.decode('punycode', 'ignore') and b'abc\xff-'.decode('punycode', 'replace') raise a UnicodeDecodeError: the error handler is just useless (ignored) here.
With my patch, b'abc\xff-'.decode('punycode', 'ignore') gives 'abc'. (If I change the code to accept replace) b'abc\xff-'.decode('punycode', 'replace') gives also 'abc', but 'replace' doesn't work correctly in the part after "-" contain illegal byte sequences.
For example, b'a\xff-\xffb\xffga\xff'.decode("punycode", "replace") gives 'a�', whereas I would expect 'a�é' or 'aé�'. b'a-bga\xff'.decode("punycode", "replace") gives 'aé' as b'a-bga'.decode("punycode", "replace"), whereas I would expect 'aé�' or something like that.
It's just that I'm unable to patch punycode decoder to support the replace handler. Do you want to "implement" it?
I don't think so because I consider that the punycode decoder never supported error handlers (other than strict) in Python 3.
What do you think?
loewis commentedon Jun 21, 2011
That's not my point:
b"foo".decode("punycode","replace")
currently succeeds, but raises an UnicodeError under the patch.
vstinner commentedon Dec 17, 2013
I prefer to not touch punycode right now, it works, there is no need to modify it.