Opened 8 years ago

Last modified 8 years ago

#25595 new Bug

Invalid regexp in URLValidator can't handle file:// schemes

Reported by: Marcin Nowak Owned by: nobody
Component: Core (Other) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Regexp does not allow to use file scheme in URLValidator.

Steps to reproduce

from django.core.validators import URLValidator
URLValidator(schemes=['file'])('file:///tmp/somefile')

Expected result

No exception should be raised.

Current result

ValidationError: [u'Enter a valid URL.']

Change History (5)

comment:1 Changed 8 years ago by Tim Graham

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted

Can this be fixed without special casing the file scheme in the validation?

comment:2 Changed 8 years ago by Claude Paroz

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 Changed 8 years ago by Tim Graham

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 Changed 8 years ago by Johannes Maron

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 with RFC 1738 schemas are supported. Currently one gets the impression that all are.

Version 0, edited 8 years ago by Johannes Maron (next)

comment:5 Changed 8 years ago by Johannes Maron

Interestingly enough, if you include the optional host parameter in RFC1738 it works: file://localhost/tmp/file/name

Note: See TracTickets for help on using tickets.
Back to Top