Skip to content

uri: upper-case schemes are rejected although url() accepts them (HTTP://EXAMPLE.COM) #584

Open

Description

Summary

uri chooses a branch with value.startswith("http"), value.startswith("mailto:"), … on the raw value, so the scheme comparison is case-sensitive. A URI whose scheme is written in upper or mixed case falls through every branch and is rejected, although url (which lower-cases the scheme through urllib.parse.urlsplit) accepts the same string.

Reproduction (master at 22786cc, Python 3.13)

>>> from validators import url
>>> from validators.uri import uri
>>> url("HTTP://EXAMPLE.COM")
True
>>> uri("HTTP://EXAMPLE.COM")
ValidationError(func=uri, args={'value': 'HTTP://EXAMPLE.COM'})
>>> uri("MAILTO:user@example.com")
ValidationError(func=uri, args={'value': 'MAILTO:user@example.com'})

Expected

RFC 3986 §3.1: "schemes are case-insensitive … an implementation should accept uppercase letters as equivalent to lowercase in scheme names". A URL accepted by url should also be accepted by uri.

Proposed fix

Lower-case the scheme (the part before the first :) before dispatching. A PR follows.


Found while writing specification-based tests for a university software-testing project (NYCU). The investigation and this write-up were done with the help of an AI assistant (Claude Code); the reproduction was run on the current master.

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