Django

Code

Ticket #6019 (closed: duplicate)

Opened 1 year ago

Last modified 1 year ago

URLField does not allow URLs starting with ftp://

Reported by: Soeren Sonnenburg <bugreports@nn7.de> Assigned to: nobody
Milestone: Component: Uncategorized
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 1
Needs tests: 0 Patch needs improvement: 0

Description

basically line 409 in newforms/fields.py is too restrictive

instead of

url_re = re.compile(
    r'^https?://' # http:// or https://
    r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
    r'localhost|' #localhost...
    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
    r'(?::\d+)?' # optional port
    r'(?:/?|/\S+)$', re.IGNORECASE)

it should rather be

url_re = re.compile(
    r'^(ftp|https?)://' # http:// or https://
    r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
    r'localhost|' #localhost...
    r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
    r'(?::\d+)?' # optional port
    r'(?:/?|/\S+)$', re.IGNORECASE)

to allow normal ftp://foo.bar urls - this works with validation too...

Attachments

Change History

11/23/07 19:04:09 changed by Alex

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Makes sense, are there any other protocols we would want to support.

11/23/07 23:49:53 changed by Soeren Sonnenburg <bugreports@nn7.de>

I could not think of anything else, e.g. mailto:// is handled in a separate field and cannot be checked the same way, file:// does not really make sense, gopher:// is not exactly popular...

11/23/07 23:52:27 changed by Soeren Sonnenburg <bugreports@nn7.de>

on the other hand, one could be future proof(tm) and add a prefix argument that defaults to url_prefix='(ftp|https?)' which is then integrated in the re ...

12/01/07 18:02:34 changed by jacob

  • status changed from new to closed.
  • resolution set to duplicate.

I've created #6092 to track the bigger issue here.

01/10/08 05:54:44 changed by anonymous

  • status changed from closed to reopened.
  • needs_docs set to 1.
  • resolution deleted.

please add rsync and nfs also

01/10/08 06:46:43 changed by ramiro

  • status changed from reopened to closed.
  • resolution set to duplicate.

Reverting anonymous reopen


Add/Change #6019 (URLField does not allow URLs starting with ftp://)




Change Properties
Action