Skip to content

idna incremental decoder decodes dots twice after leading empty labels #161102

Closed

Description

@gpshead

Bug report

Bug description:

The incremental decoder of the idna codec counts the dot before a label as consumed only if the labels before it were non-empty. After leading empty labels it returns the dot as text but leaves it in its buffer, so the next call decodes it again.

import codecs, io
d = codecs.getincrementaldecoder("idna")()
print(repr(d.decode(b".example.com") + d.decode(b"", True)))  # '.example..com'
print(len(io.TextIOWrapper(io.BytesIO(b"." * 1000), encoding="idna").readline()))  # 500500

Expected '.example.com' and 1000, as bytes.decode("idna") gives. Bytes also remain in the decoder after final=True, and the UnicodeDecodeError position for an invalid label after the first is one less than the one-shot decoder reports.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. self-assigned this
    on Nov 1, 2026
  2. added a commit that references this issue on Nov 1, 2026
  3. added 2 commits that reference this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions