Skip to content

Conversation

@algebraic-dev
Copy link
Member

@algebraic-dev algebraic-dev commented Jan 23, 2026

This PR introduces the URI data type.

This contains the same code as #10478, divided into separate pieces to facilitate easier review.

The pieces of this feature are:

@algebraic-dev algebraic-dev self-assigned this Jan 23, 2026
@algebraic-dev algebraic-dev requested a review from TwoFX as a code owner January 23, 2026 23:03
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 24, 2026
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Jan 24, 2026

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0a0323734b2d10c3f9355659f8e44b67bd36f644 --onto 57003e5c7962bd5db93fb51d4536969c3631c1db. You can force Mathlib CI using the force-mathlib-ci label. (2026-01-24 02:14:09)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0a0323734b2d10c3f9355659f8e44b67bd36f644 --onto 4c1e4a77b4952098ea043f9b8c2d155c20b24523. You can force Mathlib CI using the force-mathlib-ci label. (2026-01-25 00:36:31)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 0a0323734b2d10c3f9355659f8e44b67bd36f644 --onto e9a1c9ef63d8e53803c16077f03e2dacd4a890bd. You can force reference manual CI using the force-manual-ci label. (2026-01-24 02:14:10)

-/
def withQuery (uri : URI) (query : URI.Query) : URI :=
{ uri with query }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC 7230 Section 5.3.1 defines origin-form as:

origin-form = absolute-path [ "?" query ]

There's no fragment component—fragments are client-side only and should not be sent to servers in HTTP request targets. Should originForm exclude the fragment field, or is there a use case I'm missing?


/--
TCP port number.
-/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username and password are stored decoded (per UserInfo docstring), but this ToString instance doesn't percent-encode them before serialization. This can produce invalid/ambiguous URIs.

Test case:

-- Expected: "user%40example:pass%3Aword@host.com"
-- Actual: "user@example:pass:word@host.com" (ambiguous - multiple @ and :)
#eval toString ({
  userInfo := some ⟨"user@example", some "pass:word"⟩,
  host := .name ⟨"host.com", by decide⟩
} : URI.Authority)

Should this use EncodedString.encode for the userinfo components?

if (← peekWhen? (· == '['.toUInt8)).isSome then
return .ipv6 (← parseIPv6)
else if (← peekWhen? isDigit).isSome then
return .ipv4 (← parseIPv4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domain names can start with digits (RFC 1123 relaxed RFC 952). A host like 1example.com would trigger the IPv4 branch, fail validation in Net.IPv4Addr.ofString, and not fall back to reg-name parsing.

Should there be a fallback to reg-name if IPv4 parsing fails? Or is rejecting digit-leading domain names intentional?

-/
fragment : Option String := none
deriving Inhabited

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says "The domain name will be automatically percent-encoded" but the implementation just lowercases—no percent-encoding happens. (Domain names typically use punycode for internationalization rather than percent-encoding anyway.) Should the docstring be corrected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants