Opened 9 years ago

Closed 9 years ago

#11826 closed (fixed)

django.forms.fields.URLField rejects valid URLs with no abs_path component

Reported by: wam Owned by: Honza Král
Component: Forms Version: master
Severity: Keywords:
Cc: Triage Stage: Fixed on a branch
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As annoying as it is, RFC 2616 section 3.2.2 ( allows the abs_path component (the pathname following the optional port number) to be optional in an HTTP URL (it implicitly becomes '/', and is required to treated as '/' for sake of comparisons as well as for request processing). However, the definition of django.forms.fields.url_re requires the character following the optional port number to be a /. The regex also allows the URL to just end after the port with no abs_path, but it currently rejects URLs like:

Additionally, the clean() method tacks on a trailing slash to URLs that don't have a pathname.

Attached to this ticket will be a patch to django/forms/ which properly handles URLs like the one listed above by normalizing it to the version that is suitable for URI comparison (see The patch will also provide an additional testcase to tests/regressiontests/forms/ which includes the URL above along with it's expected normalization.

Attachments (1)

rfc2616-ticket11826.patch (1.8 KB) - added by wam 9 years ago.
Patch to url_re to allow URLs with no abs_name component, plus testcase

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by wam

Attachment: rfc2616-ticket11826.patch added

Patch to url_re to allow URLs with no abs_name component, plus testcase

comment:1 Changed 9 years ago by Honza Král

Owner: changed from nobody to Honza Král
Triage Stage: UnreviewedFixed on a branch

Fixed on model-validation branch in [11525]

comment:2 Changed 9 years ago by Honza Král

Resolution: fixed
Status: newclosed

With model-validation merged, this is fixed in [12098]

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