Skip to content

urllib.parse.urljoin incorrectly collapses repeated slashes in relative paths #158767

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: urljoin's docstring promises: "Join a base URL and a possibly relative URL to form an absolute interpretation of the latter." The module documentation states: "RFC 3986 is considered the current standard and any future changes to urllib.parse module should conform with it." RFC 3986 sections 5.2.3–5.2.4 specify path merging and dot-segment removal; empty interior segments are not dot segments.

Expected: https://example.com/a/b//c

Actual: https://example.com/a/b/c

import re
import urllib.parse

base, r = "https://example.com/a/", "b//c"
if not re.fullmatch(r"[A-Za-z]+(?:/+[A-Za-z]+)*", r):
    print("REFUTATION REJECTED:", "input is outside the claimed domain")
else:
    actual = urllib.parse.urljoin(base, r)
    # RFC 3986: merge with the base directory; no dot segments to remove.
    expected = base + r
    if actual != expected:
        print("REFUTATION CONFIRMED:", repr(r), repr(actual), repr(expected))
    else:
        print("REFUTATION REJECTED:", "actual equals the RFC expectation")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library urllib.parse:

REFUTATION CONFIRMED: 'b//c' 'https://example.com/a/b/c' 'https://example.com/a/b//c'

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/urllib.parse-20261003-015128-c3

CPython versions tested on:

3.14

Operating systems tested on:

Windows

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions