1
0
mirror of https://github.com/django/django.git synced 2025-08-10 20:09:12 +00:00

Fixed #5192 -- Modified flatpage admin form to allow ~ and . characters in flatpage names. Thanks to marco.giusti@gmail.com for the report, Idan Gazit for summarizing the issue on the ticket, and ctrochalakis for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13655 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2010-08-28 12:25:54 +00:00
parent e1e2726957
commit 72a7167439
4 changed files with 41 additions and 2 deletions

View File

@ -5,11 +5,11 @@ from django.utils.translation import ugettext_lazy as _
class FlatpageForm(forms.ModelForm): class FlatpageForm(forms.ModelForm):
url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/]+$', url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/\.~]+$',
help_text = _("Example: '/about/contact/'. Make sure to have leading" help_text = _("Example: '/about/contact/'. Make sure to have leading"
" and trailing slashes."), " and trailing slashes."),
error_message = _("This value must contain only letters, numbers," error_message = _("This value must contain only letters, numbers,"
" underscores, dashes or slashes.")) " dots, underscores, dashes, slashes or tildes."))
class Meta: class Meta:
model = FlatPage model = FlatPage

View File

@ -1,4 +1,5 @@
from django.contrib.flatpages.tests.csrf import * from django.contrib.flatpages.tests.csrf import *
from django.contrib.flatpages.tests.forms import *
from django.contrib.flatpages.tests.middleware import * from django.contrib.flatpages.tests.middleware import *
from django.contrib.flatpages.tests.templatetags import * from django.contrib.flatpages.tests.templatetags import *
from django.contrib.flatpages.tests.views import * from django.contrib.flatpages.tests.views import *

View File

@ -0,0 +1,22 @@
from django.contrib.flatpages.admin import FlatpageForm
from django.test import TestCase
class FlatpageAdminFormTests(TestCase):
def setUp(self):
self.form_data = {
'title': "A test page",
'content': "This is a test",
'sites': [1],
}
def test_flatpage_admin_form_url_validation(self):
"The flatpage admin form validates correctly validates urls"
self.assertTrue(FlatpageForm(data=dict(url='/new_flatpage/', **self.form_data)).is_valid())
self.assertTrue(FlatpageForm(data=dict(url='/some.special~chars/', **self.form_data)).is_valid())
self.assertTrue(FlatpageForm(data=dict(url='/some.very_special~chars-here/', **self.form_data)).is_valid())
self.assertFalse(FlatpageForm(data=dict(url='/a space/', **self.form_data)).is_valid())
self.assertFalse(FlatpageForm(data=dict(url='/a % char/', **self.form_data)).is_valid())
self.assertFalse(FlatpageForm(data=dict(url='/a ! char/', **self.form_data)).is_valid())
self.assertFalse(FlatpageForm(data=dict(url='/a & char/', **self.form_data)).is_valid())
self.assertFalse(FlatpageForm(data=dict(url='/a ? char/', **self.form_data)).is_valid())

View File

@ -1,6 +1,7 @@
import os import os
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase from django.test import TestCase
class FlatpageViewTests(TestCase): class FlatpageViewTests(TestCase):
@ -54,3 +55,18 @@ class FlatpageViewTests(TestCase):
"A non-existent flatpage won't be served if the fallback middlware is disabled" "A non-existent flatpage won't be served if the fallback middlware is disabled"
response = self.client.get('/no_such_flatpage/') response = self.client.get('/no_such_flatpage/')
self.assertEquals(response.status_code, 404) self.assertEquals(response.status_code, 404)
def test_view_flatpage_special_chars(self):
"A flatpage with special chars in the URL can be served through a view"
fp = FlatPage.objects.create(
url="/some.very_special~chars-here/",
title="A very special page",
content="Isn't it special!",
enable_comments=False,
registration_required=False,
)
fp.sites.add(1)
response = self.client.get('/flatpage_root/some.very_special~chars-here/')
self.assertEquals(response.status_code, 200)
self.assertContains(response, "<p>Isn't it special!</p>")