Add IDN (Internationalized Domain Name) support to URL validator#2927
Closed
rstar327 wants to merge 2 commits intomarshmallow-code:devfrom
Closed
Add IDN (Internationalized Domain Name) support to URL validator#2927rstar327 wants to merge 2 commits intomarshmallow-code:devfrom
rstar327 wants to merge 2 commits intomarshmallow-code:devfrom
Conversation
…L validator Convert Unicode hostnames to punycode (IDNA encoding) before regex validation so that URLs like https://তৌহিদুর.বাংলা are accepted. Fixes marshmallow-code#2821
Member
|
@rstar327 are you a user of marshmallow and do you have any stake in this particular feature being implemented? |
Contributor
Author
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. |
Member
|
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 |
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.
Add support for Internationalized Domain Names (IDN) in the
URLvalidator.URLs with Unicode hostnames like
https://তৌহিদুর.বাংলাandhttps://münchen.deare 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