Code

Opened 5 years ago

Closed 5 years ago

#9918 closed (worksforme)

URL field validation false negative

Reported by: aglzen Owned by: nobody
Component: Forms Version: 1.0
Severity: Keywords: URLField validation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hello,

Just reporting that the validation for URLFields fails incorrectly with URLs similar to the below.

http://foo.com/1-2.html#bar

Original case:
http://www.ens-newswire.com/ens/jun2007/2007-06-05-09.asp#anchor2

is incorrectly rejected.

Attachments (0)

Change History (5)

comment:1 Changed 5 years ago by oggy

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

Cannot reproduce with v9690. The URLField regex seems OK to me.

In [10]: from django import forms

In [11]: f = forms.URLField()

In [12]: f.clean('http://www.ens-newswire.com/ens/jun2007/2007-06-05-09.asp#abc')
Out[12]: u'http://www.ens-newswire.com/ens/jun2007/2007-06-05-09.asp#abc'

comment:2 Changed 5 years ago by ubernostrum

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

comment:3 Changed 5 years ago by aglzen

I definitely have a plain-vanilla URLField that fails on that url and the cases noted above in real usage (oggy's code works fine for me). Will dig into this and see what's happening.

comment:4 Changed 5 years ago by aglzen

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Nope, this is definitely an issue. I haven't been able to track down what's causing it, but I get it in a brand-new app, for an otherwise well-behaved URLField.

To reproduce, try entering one of the above URLs into any admin interface URLField, or use an app like the below:

urls.py:

from django.conf.urls.defaults import *
from test_app.models import *
urlpatterns = patterns('django.views.generic.create_update',
    (r'^', 'create_object',{'model':TestModel}),
)

settings.py:

ROOT_URLCONF = 'urls'

import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates')
)

INSTALLED_APPS = (
	'test_app',
)

test_app/models.py:

from django.db import models

# Create your models here.
class TestModel(models.Model):
	test_url = models.URLField()

templates/test_app/testmodel_form.html

<html><head></head>
<body>
	<form action="." method="POST">
	{{form}}
	<input type="submit"/>
	</form>
</body>

On runserver, and load of 127.0.0.1:8000, enter one of the URLs in the original ticket, and receive "This URL appears to be a broken link."

comment:5 Changed 5 years ago by kratorius

  • Resolution set to worksforme
  • Status changed from reopened to closed

You get that error because verify_exists is True on models.URLField (see http://docs.djangoproject.com/en/dev/ref/models/fields/#urlfield). In other words it will make sure that the above URLs won't return a 404. If you don't need this functionality just set verify_exists to False (and it gives a that error on the second URL because that particular server will return a 400 error code for that).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.