Skip to content

uri_to_iri and iri_to_uri drop an empty username or password #3189

Closed
alguemqualquer123/werkzeug
#1

Description

@nyxst4ck

uri_to_iri() and iri_to_uri() reconstruct the userinfo part of a URL using a truthiness check on username / password. Because an empty string is falsy, an empty-but-present username or password is silently dropped, even though urllib.parse.urlsplit distinguishes a present-but-empty component ("") from a missing one (None).

Replicate:

>>> from werkzeug.urls import uri_to_iri, iri_to_uri
>>> uri_to_iri("http://:pass@example.com/path")
'http://example.com/path'        # password silently dropped
>>> uri_to_iri("http://user:@example.com/path")
'http://user@example.com/path'   # empty password separator dropped
>>> iri_to_uri("http://:pass@example.com/path")
'http://example.com/path'

For comparison, the stdlib round-trips these correctly:

>>> from urllib.parse import urlsplit, urlunsplit
>>> urlunsplit(urlsplit("http://:pass@example.com/path"))
'http://:pass@example.com/path'

The first case is the most concerning: a non-empty password is dropped entirely when the username is empty, which is data loss during what should be a lossless normalization.

Expected behavior: an empty username or password that is present in the input should be preserved. Only a missing component (None) should be omitted.

Environment:

  • Python version: 3.11
  • Werkzeug version: main (3.2.0.dev)

Activity

  1. deleted a comment from mangodxd on Jul 16, 2026
  2. added this to the 3.1.9 milestone on Jul 30, 2026
  3. locked as resolved and limited conversation to collaborators on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions