diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
index fecbff7..a15f4de 100644
a
|
b
|
|
1 | 1 | from django.db import models |
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
| 3 | from django.core.exceptions import ValidationError |
3 | 4 | |
4 | 5 | |
5 | 6 | SITE_CACHE = {} |
… |
… |
class Site(models.Model):
|
61 | 62 | except KeyError: |
62 | 63 | pass |
63 | 64 | |
| 65 | def clean(self): |
| 66 | if ' ' in self.domain: |
| 67 | raise ValidationError('Domain name cannot contain any whitespace.') |
| 68 | |
| 69 | |
64 | 70 | |
65 | 71 | class RequestSite(object): |
66 | 72 | """ |
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 3a80ffc..1d76e38 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | from django.contrib.sites.models import Site, RequestSite, get_current_site |
3 | 3 | from django.contrib.sites.middleware import SiteMiddleware |
4 | | from django.core.exceptions import ObjectDoesNotExist |
| 4 | from django.core.exceptions import ObjectDoesNotExist, ValidationError |
5 | 5 | from django.http import HttpRequest |
6 | 6 | from django.test import TestCase |
7 | 7 | |
… |
… |
class SitesFrameworkTests(TestCase):
|
56 | 56 | self.assertTrue(isinstance(site, RequestSite)) |
57 | 57 | self.assertEqual(site.name, u"example.com") |
58 | 58 | |
| 59 | def test_domain_cannot_contain_whitespace(self): |
| 60 | site = Site.objects.get_current() |
| 61 | site.domain = 'domain contains\twhitespaces\n' |
| 62 | self.assertRaises(ValidationError, site.full_clean) |
| 63 | |
59 | 64 | class MiddlewareTest(TestCase): |
60 | 65 | |
61 | 66 | def test_request(self): |