feat(url): improve recall for localhost, IP literals, and uppercase TLDs - #9
Draft
ClaudiuCeia with Copilot wants to merge 3 commits into
Draft
feat(url): improve recall for localhost, IP literals, and uppercase TLDs#9ClaudiuCeia with Copilot wants to merge 3 commits into
ClaudiuCeia with Copilot wants to merge 3 commits into
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The URL parser missed several structurally unambiguous forms:
localhost, IPv4/IPv6 literals, domains with internal hyphens, uppercase TLDs, and URLs likehttps://example.com/a).where trailing punctuation should be excluded from the span.Authority handling — split by context
Protocol-qualified URLs (
https://…) now use a dedicatedFullHostparser that accepts any valid hostname without an IANA TLD requirement:[2001:db8::1]127.0.0.1my-site.example.com,münchen.deBare domains (no protocol) continue to require a valid IANA TLD, keeping false-positive rate low.
TLD matching
longestLiteralis now called with{ caseInsensitive: true }, so.COM,.COMMUNITY,.рф,.XN--P1AIetc. all match.value.urlis 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::1.5by checking for a following.:0and:65536Suffix trimming
The
Suffixparser now strips trailing unmatched closing punctuation by counting opener vs. closer occurrences: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.