Skip to content

Add IDN (Internationalized Domain Name) support to URL validator#2927

Closed
rstar327 wants to merge 2 commits intomarshmallow-code:devfrom
rstar327:add-idn-url-support
Closed

Add IDN (Internationalized Domain Name) support to URL validator#2927
rstar327 wants to merge 2 commits intomarshmallow-code:devfrom
rstar327:add-idn-url-support

Conversation

@rstar327
Copy link
Copy Markdown
Contributor

Add support for Internationalized Domain Names (IDN) in the URL validator.

URLs with Unicode hostnames like https://তৌহিদুর.বাংলা and https://münchen.de are currently always rejected because the hostname regex only accepts ASCII characters.

The fix converts Unicode hostnames to punycode (IDNA encoding) before regex validation using Python's built-in str.encode('idna'). The original URL value is preserved and returned — only the validation step uses the encoded form.

All 1149 existing tests pass.

Fixes #2821

…L validator

Convert Unicode hostnames to punycode (IDNA encoding) before regex
validation so that URLs like https://তৌহিদুর.বাংলা are accepted.

Fixes marshmallow-code#2821
@sloria
Copy link
Copy Markdown
Member

sloria commented Mar 26, 2026

@rstar327 are you a user of marshmallow and do you have any stake in this particular feature being implemented?

@rstar327
Copy link
Copy Markdown
Contributor Author

@rstar327 are you a user of marshmallow and do you have any stake in this particular feature being implemented?

Not a heavy user, but I saw the open issue and the fix was clean, just IDNA encoding before the existing regex. Happy to take feedback on the approach.

@sloria
Copy link
Copy Markdown
Member

sloria commented Mar 26, 2026

looking into this a bit more, i think we can take Django's simpler approach which is to relax the regex to allow unicode chars. See https://github.com/django/django/blob/f6167b8bc881babd19b67c004e8f37954afc192e/django/core/validators.py#L71-L85 . I've made a PR with this approach in #2928

@sloria sloria closed this Apr 1, 2026
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.

There is not way to make marshmallow.validate.URL accept IDNs (Internationalized Domain Names)

2 participants