Opened 3 years ago

Closed 3 years ago

#21242 closed New feature (fixed)

Allow more IANA schemes in URLValidator

Reported by: saschpe Owned by: saschpe
Component: Core (Other) Version: master
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


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:// 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)


Change History (7)

comment:1 Changed 3 years ago by saschpe

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

So addresses at least the ssh example, but I'd rather want to generalize URLValidator further.

comment:2 Changed 3 years ago by claudep

  • Component changed from Uncategorized to Core (Other)
  • Has patch set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to New feature
  • Version changed from 1.5 to master

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 Changed 3 years ago by saschpe

  • Owner changed from nobody to saschpe
  • Status changed from new to assigned

comment:5 Changed 3 years ago by claudep

  • Patch needs improvement unset

I've provided an alternative patch, based on Sascha's patch:

comment:6 Changed 3 years ago by timo

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 3 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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