Skip to content

feat(url): improve recall for localhost, IP literals, and uppercase TLDs - #9

Draft
ClaudiuCeia with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-url-recall
Draft

feat(url): improve recall for localhost, IP literals, and uppercase TLDs#9
ClaudiuCeia with Copilot wants to merge 3 commits into
mainfrom
copilot/improve-url-recall

Conversation

Copilot AI commented Jul 25, 2026

Copy link
Copy Markdown

The URL parser missed several structurally unambiguous forms: localhost, IPv4/IPv6 literals, domains with internal hyphens, uppercase TLDs, and URLs like https://example.com/a). where trailing punctuation should be excluded from the span.

Authority handling — split by context

Protocol-qualified URLs (https://…) now use a dedicated FullHost parser that accepts any valid hostname without an IANA TLD requirement:

  • Bracketed IPv6[2001:db8::1]
  • IPv4 literals127.0.0.1
  • localhost and other internal names
  • DNS names with hyphens and Unicode labelsmy-site.example.com, münchen.de

Bare domains (no protocol) continue to require a valid IANA TLD, keeping false-positive rate low.

TLD matching

longestLiteral is now called with { caseInsensitive: true }, so .COM, .COMMUNITY, .рф, .XN--P1AI etc. all match. value.url is derived from raw input text (b.text.substring(b.index, a.index)) so original casing is preserved.

Port validation

Replaced the generic number() combinator with a hand-written integer parser:

  • Digit-only scan — rejects :1.5 by checking for a following .
  • Range guard — rejects :0 and :65536

Suffix trimming

The Suffix parser now strips trailing unmatched closing punctuation by counting opener vs. closer occurrences:

See https://example.com/a).  →  span: https://example.com/a

Balanced brackets inside the path (e.g. /(foo)) are preserved.

Bare domain label regex

Changed from \w+ to [a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?, allowing internal hyphens while excluding leading/trailing hyphens per RFC 1123.

Copilot AI added 2 commits July 25, 2026 13:26
- TLD matching is now case-insensitive (service.COM, service.COMMUNITY now match)
- Full URL authority (after ://) accepts localhost, IPv4 literals, bracketed
  IPv6 ([2001:db8::1]), DNS names with internal hyphens, and Unicode labels
  without requiring an IANA TLD
- Bare domain parser label regex updated to allow internal hyphens
- Port parser validates integer 1-65535; rejects decimals (:1.5) and out-of-
  range values (:65536); uses raw digit scan instead of number()
- Suffix parser trims trailing unmatched closing punctuation (e.g. https://example.com/a). becomes /a)
- Full and Bare parsers now derive value.url from raw input text, preserving
  original case
- Tests: flip lowercase-only TLD test; add 10 new tests covering all gaps
- Remove underscore from fullHostParser label character classes (not
  valid in standard DNS labels per RFC 1123)
- Improve trimUrlSuffix bracket counting: use open/close occurrence
  counts instead of simple presence check (correctly handles cases like
  (foo](bar) where same-type counts matter)
- Add value assertions to port rejection tests
Copilot AI changed the title [WIP] Improve recall for localhost, IP literals, uppercase TLDs feat(url): improve recall for localhost, IP literals, and uppercase TLDs Jul 25, 2026
Copilot AI requested a review from ClaudiuCeia July 25, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

url: improve recall for localhost, IP literals, uppercase TLDs

2 participants