fix: support punycode TLDs in URL regex#666
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated ChangesPunycode Domain Support
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/helpers.ts`:
- Line 133: The punycode TLD branch in the hostname regex uses the
too-permissive fragment "xn--[a-z\\d-]+", which allows labels ending with a
hyphen; update that fragment to enforce the same edge constraints as regular
labels by replacing it with "xn--[a-z\\d]([a-z\\d-]*[a-z\\d])?" so the punycode
label cannot start or end with a hyphen (refer to the existing label pattern
([a-z\\d]([a-z\\d-]*[a-z\\d])*) to mirror its behavior).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: da7fb532-2206-4e6a-be2f-9eedf30684ab
📒 Files selected for processing (1)
src/utils/helpers.ts
…iling hyphens (RFC 1035 compliance).
Issue ticket number and link
No related issue — this is a small self-contained fix.
Documentation
Select exactly one:
Internal regex fix in URL validation — no user-facing behavior or API changes, so documentation update is not required.
Summary
Update the URL validation regex to support internationalized domain names (IDN) in Punycode format.
Problem
The current regex rejects valid IDN TLDs because the TLD part only allows letters:
As a result, URLs with Punycode TLDs fail validation, even though they are perfectly valid. Examples of such TLDs:
.xn--p1ai.xn--fiqs8s.xn--qxam.xn--mgba3a4f16aSolution
Split the TLD matching into two cases:
.com,.org,.net)xn--prefix followed by letters, digits and hyphens (e.g..xn--p1ai,.xn--fiqs8s)Test cases
https://example.comhttps://example.orghttps://example.xn--p1aihttps://example.xn--fiqs8shttps://xn--80adjurfhd.xn--c1aao5a.xn--p1aihttp://localhost:3000https://192.168.0.1/pathNotes
tldts) with the Public Suffix List, since the set of TLDs changes over time.Summary by CodeRabbit