kjd / idna

Internationalized Domain Names for Python (IDNA 2008 and UTS #46)
BSD 3-Clause "New" or "Revised" License
247 stars 91 forks source link

Fix _buffer_encode() wrong return type. #144

Closed elliotwutingfeng closed 1 year ago

elliotwutingfeng commented 1 year ago

Current implementation of _buffer_encode() has the wrong type signature (expected bytes but got str). It also attempts to perform a str.join() on list[bytes].

Fixes #138

jribbens commented 1 year ago

Hmm it seems rather unimpressive that mypy does not spot that str.join(list[bytes]) will fail.

There is a wider issue here. The codec decoder also doesn't work properly. The existing tests in test_idna_codec.py should be noticing both of these issues, except that, even after import idna.codec, codecs.lookup('idna') is still returning the Python standard library codec instead of the one from this library, so the tests are just testing the Python codec instead of this library's one.

sethmlarson commented 1 year ago

I noted here that the codec implementation appears to be untested, broken, and likely unused. https://github.com/kjd/idna/issues/134

elliotwutingfeng commented 1 year ago

I see. I think further discussion would be needed before attempting to fix this.

jribbens commented 1 year ago

@elliotwutingfeng I think your fix was fine, I have incorporated it into my PR #145 which also fixes the other issues.

elliotwutingfeng commented 1 year ago

Thanks! Yes, it is better to consolidate all the fixes into one PR.