Opened 12 years ago
Last modified 5 years ago
#18517 closed Bug
URLField does not support url with underscore — at Initial Version
Reported by: | guoqiao | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 1.6 |
Severity: | Normal | Keywords: | URLFiled |
Cc: | guoqiao | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
if your url has a '_' in it, like this:
http://django_compressor.readthedocs.org/
the URLField will complain that it is not a valid url. the problem lies in the '_' symbol. I find in the source code as Following:
class URLValidator(RegexValidator):
regex = re.compile(
r'(?:http|ftp)s?:' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
r'localhost|' #localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|/\S+)$', re.IGNORECASE)
the related part is this line:
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
It's clear that '_' is not included in the pattern.
I think this is not reaonable for there's a lot of url has a '_' in it.