#25595 closed Bug (fixed)
Invalid regexp in URLValidator can't handle file:// schemes
Description ¶
Change History (9)
comment:1 by , 9 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 9 years ago
It's URLValidator
not URIValidator
, I think you might need your own custom validator for this. The current regex is already bloated, I'm not sure we should continue to complexify it...
comment:3 by , 9 years ago
I had a similar skepticism. If we don't make a change, then let's clarify the documentation to prevent further tickets about this.
comment:4 by , 9 years ago
I thinks this is both a documentation and code problem. The URLValidator
should raise a value error, if a unsupported schema is set. In the documentation it should be explained which schemas are supported. Currently one gets the impression that all are.
comment:5 by , 9 years ago
Interestingly enough, if you include the optional host parameter in RFC1738 it works: file://localhost/tmp/file/name
comment:6 by , 12 months ago
Cc: | added |
---|---|
Has patch: | set |
Owner: | changed from | to
Status: | new → assigned |
I opened a PR adding a warning about this to the documentation. I'm happy to handle it in a different way if that'd be better.
For what it's worth, if someone out there wants to validate local file URIs in addition to URLs, here is an idea to start with:
@deconstructible class CustomURLValidator(URLValidator): def __init__(self, **kwargs): super().__init__(**kwargs) self.schemes.append('file') def __call__(self, value): if value.startswith('file:///'): value = value.replace('file:///', 'file://localhost/', 1) return super().__call__(value)
comment:7 by , 12 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Can this be fixed without special casing the file scheme in the validation?