Opened 10 years ago

Closed 10 years ago

#21242 closed New feature (fixed)

Allow more IANA schemes in URLValidator

Reported by: Sascha Peilicke Owned by: Sascha Peilicke
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, URLValidator only allows the following schemes: http(s) and ftp(s). Since the formal definition of URL (being a subset of URI) includes many more valid schemes [1], URLValidator should be expanded to allow those. Of course Django users could create their own validator but this seems to be a rather common task it's probably better to have that in core Django.

An alternative solution would be to provide an URIValidator which allows more schemes than what we currently have in URLValidator. However, since sth. like ssh://example.com is not only a valid URI but also a valid URL [2] it doesn't seem to make sense to differentiate URI and URL.

Related to that, #15229 already added support for ftp(s)

[1] https://en.wikipedia.org/wiki/URI_scheme#Official_IANA-registered_schemes
[2] https://tools.ietf.org/html/rfc3986

Change History (7)

comment:1 by Sascha Peilicke, 10 years ago

So https://github.com/django/django/pull/1717 addresses at least the ssh example, but I'd rather want to generalize URLValidator further.

comment:2 by Claude Paroz, 10 years ago

Component: UncategorizedCore (Other)
Has patch: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Version: 1.5master

Yes, this might be interesting, but only if we generalize accepted schemes. We should probably add a new scheme init parameter allowing to specify a scheme list (defaulting to ['http', 'https', 'ftp', 'ftps']), and then check for valid schemes in __call__.

comment:3 by Sascha Peilicke, 10 years ago

Owner: changed from nobody to Sascha Peilicke
Status: newassigned

comment:5 by Claude Paroz, 10 years ago

Patch needs improvement: unset

I've provided an alternative patch, based on Sascha's patch: https://github.com/django/django/pull/2099

comment:6 by Tim Graham, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 6d66ba59488bbd0d4f0c2f32b2921f1512301143:

Fixed #21242 -- Allowed more IANA schemes in URLValidator

Thanks Sascha Peilicke for the report and initial patch, and
Tim Graham for the review.

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