Opened 6 years ago

Closed 5 years ago

#11826 closed (fixed)

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

Reported by: wam Owned by: Honza_Kral
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: UI/UX:

Description

As annoying as it is, RFC 2616 section 3.2.2 (http://www.rfc2616.com/#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:

http://example.com?some_param=some_value

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/fields.py which properly handles URLs like the one listed above by normalizing it to the version that is suitable for URI comparison (see http://www.rfc2616.com/#3.2.3). The patch will also provide an additional testcase to tests/regressiontests/forms/fields.py which includes the URL above along with it's expected normalization.

Attachments (1)

rfc2616-ticket11826.patch (1.8 KB) - added by wam 6 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 6 years ago by wam

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

comment:1 Changed 6 years ago by Honza_Kral

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to Honza_Kral
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Fixed on a branch

Fixed on model-validation branch in [11525]

comment:2 Changed 5 years ago by Honza_Kral

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

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

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