Opened 12 years ago

Closed 12 years ago

#9918 closed (worksforme)

URL field validation false negative

Reported by: Steven Skoczen 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: no UI/UX: no



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

Original case:

is incorrectly rejected.

Change History (5)

comment:1 Changed 12 years ago by oggy

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('')
Out[12]: u''

comment:2 Changed 12 years ago by James Bennett

Resolution: worksforme
Status: newclosed

comment:3 Changed 12 years ago by Steven Skoczen

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 12 years ago by Steven Skoczen

Resolution: worksforme
Status: closedreopened

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:

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


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



from django.db import models

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


	<form action="." method="POST">
	<input type="submit"/>

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

comment:5 Changed 12 years ago by Ivan Giuliani

Resolution: worksforme
Status: reopenedclosed

You get that error because verify_exists is True on models.URLField (see 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).

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