mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +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:
parent
e1e2726957
commit
72a7167439
@ -5,11 +5,11 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
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"
|
||||
" and trailing slashes."),
|
||||
error_message = _("This value must contain only letters, numbers,"
|
||||
" underscores, dashes or slashes."))
|
||||
" dots, underscores, dashes, slashes or tildes."))
|
||||
|
||||
class Meta:
|
||||
model = FlatPage
|
||||
|
@ -1,4 +1,5 @@
|
||||
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.templatetags import *
|
||||
from django.contrib.flatpages.tests.views import *
|
||||
|
22
django/contrib/flatpages/tests/forms.py
Normal file
22
django/contrib/flatpages/tests/forms.py
Normal 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())
|
@ -1,6 +1,7 @@
|
||||
import os
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.flatpages.models import FlatPage
|
||||
from django.test import 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"
|
||||
response = self.client.get('/no_such_flatpage/')
|
||||
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>")
|
||||
|
Loading…
Reference in New Issue
Block a user