Ticket #17320: 17320.diff

File 17320.diff, 1.6 KB (added by Christopher Medrela, 13 years ago)
  • django/contrib/sites/models.py

    diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
    index fecbff7..a15f4de 100644
    a b  
    11from django.db import models
    22from django.utils.translation import ugettext_lazy as _
     3from django.core.exceptions import ValidationError
    34
    45
    56SITE_CACHE = {}
    class Site(models.Model):  
    6162        except KeyError:
    6263            pass
    6364
     65    def clean(self):
     66        if ' ' in self.domain:
     67            raise ValidationError('Domain name cannot contain any whitespace.')
     68
     69
    6470
    6571class RequestSite(object):
    6672    """
  • django/contrib/sites/tests.py

    diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
    index 3a80ffc..1d76e38 100644
    a b  
    11from django.conf import settings
    22from django.contrib.sites.models import Site, RequestSite, get_current_site
    33from django.contrib.sites.middleware import SiteMiddleware
    4 from django.core.exceptions import ObjectDoesNotExist
     4from django.core.exceptions import ObjectDoesNotExist, ValidationError
    55from django.http import HttpRequest
    66from django.test import TestCase
    77
    class SitesFrameworkTests(TestCase):  
    5656        self.assertTrue(isinstance(site, RequestSite))
    5757        self.assertEqual(site.name, u"example.com")
    5858
     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
    5964class MiddlewareTest(TestCase):
    6065
    6166    def test_request(self):
Back to Top