Skip to content

URL.click('?') retains the base query instead of clearing it #207

Open

Description

@agammann

On main commit 978f2e645578aad856fe5e03e2e2c017c8c0f7ca, resolving a query-only reference with an empty query leaves the base query in place.

from hyperlink import URL
from urllib.parse import urljoin

base = "http://a/b/c?x=1"
print(URL.from_text(base).click("?").to_text())
print(urljoin(base, "?"))
print(URL.from_text(base).click("?y=2").to_text())

Observed:

http://a/b/c?x=1
http://a/b/c?
http://a/b/c?y=2

The last call is a nonempty-query control. RFC 3986 section 5.2.2 says a defined query on a reference with an empty path replaces the base query, even when the query is empty. The expected target is therefore http://a/b/c?.

URL.from_text("http://a/b/c?").to_text() also drops the trailing question mark, so the parser appears to lose the distinction between an absent query and a present-but-empty query. This affects links intended to clear existing query parameters.

Activity

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions