Skip to content

IPv6 literals in connection strings are not parsed correctly #104

@felixdoerre

Description

@felixdoerre

When I try to specify the postgresql iri as pq://[::1]:5432/database the connection fails.
This URL is explicitly allowed and stated that it is correct in this comment: https://github.com/python-postgres/fe/blob/master/postgresql/iri.py#L13

The reason why this happens is broken parsing here:

cpd['host'] = host[1:-1]

This results in : being used as a host, which is not valid. When a host is detected, that is enclosed in square brackets, the square brackes are removed and it is either parsed as unix domain socket:

pq://[unix::var:run:postgresql]/database (probably, I didn't find any documentation for that syntax)

Or, alternatively we just remove the first and last char again. This is wrong.
As a "workaround" one can (currently) specify ipv6-literal addresses like this:

pq://[_::1_]/database

Where the underscore is arbitrary (apart from ]/ and other url-special-characters).

I believe the correct fix would be to just remove the else branch (as I don't understand which URLs that might be needed for) and add a test case, so IPv6 literals are not broken accidentally anymore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions