Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
c7294614
Kaydet (Commit)
c7294614
authored
Şub 24, 2013
tarafından
Horst Gutmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #17320 -- Added whitespace validation to the Site.domain field
üst
99edbe0e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
models.py
django/contrib/sites/models.py
+18
-1
tests.py
django/contrib/sites/tests.py
+11
-1
No files found.
django/contrib/sites/models.py
Dosyayı görüntüle @
c7294614
import
string
from
django.db
import
models
from
django.db.models.signals
import
pre_save
,
pre_delete
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.encoding
import
python_2_unicode_compatible
from
django.core.exceptions
import
ValidationError
SITE_CACHE
=
{}
def
_simple_domain_name_validator
(
value
):
"""
Validates that the given value contains no whitespaces to prevent common
typos.
"""
if
not
value
:
return
checks
=
((
s
in
value
)
for
s
in
string
.
whitespace
)
if
any
(
checks
):
raise
ValidationError
(
_
(
u"The domain name cannot contain any spaces or tabs."
))
class
SiteManager
(
models
.
Manager
):
def
get_current
(
self
):
...
...
@@ -37,7 +53,8 @@ class SiteManager(models.Manager):
@python_2_unicode_compatible
class
Site
(
models
.
Model
):
domain
=
models
.
CharField
(
_
(
'domain name'
),
max_length
=
100
)
domain
=
models
.
CharField
(
_
(
'domain name'
),
max_length
=
100
,
validators
=
[
_simple_domain_name_validator
])
name
=
models
.
CharField
(
_
(
'display name'
),
max_length
=
50
)
objects
=
SiteManager
()
...
...
django/contrib/sites/tests.py
Dosyayı görüntüle @
c7294614
...
...
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
from
django.conf
import
settings
from
django.contrib.sites.models
import
Site
,
RequestSite
,
get_current_site
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
,
ValidationError
from
django.http
import
HttpRequest
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
...
...
@@ -71,3 +71,13 @@ class SitesFrameworkTests(TestCase):
site
=
get_current_site
(
request
)
self
.
assertTrue
(
isinstance
(
site
,
RequestSite
))
self
.
assertEqual
(
site
.
name
,
"example.com"
)
def
test_domain_name_with_whitespaces
(
self
):
# Regression for #17320
# Domain names are not allowed contain whitespace characters
site
=
Site
(
name
=
"test name"
,
domain
=
"test test"
)
self
.
assertRaises
(
ValidationError
,
site
.
full_clean
)
site
.
domain
=
"test
\t
test"
self
.
assertRaises
(
ValidationError
,
site
.
full_clean
)
site
.
domain
=
"test
\n
test"
self
.
assertRaises
(
ValidationError
,
site
.
full_clean
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment