Force collation when comparing Denied Names to avoid unwanted collisions (#22767)
* Force collation when comparing Denied Names to avoid unwanted collisions
This commit is contained in:
Родитель
6db9be4b2d
Коммит
c31188ca7d
|
@ -17,6 +17,7 @@ from django.core import validators
|
|||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import models
|
||||
from django.db.models import F, Value
|
||||
from django.db.models.functions import Collate
|
||||
from django.template import loader
|
||||
from django.templatetags.static import static
|
||||
from django.urls import reverse
|
||||
|
@ -739,7 +740,9 @@ class DeniedName(ModelBase):
|
|||
"""
|
||||
return (
|
||||
DeniedName.objects.annotate(
|
||||
query_field=Value(value, output_field=models.CharField())
|
||||
query_field=Collate(
|
||||
Value(value, output_field=models.CharField()), 'utf8mb4_0900_ai_ci'
|
||||
)
|
||||
)
|
||||
.filter(query_field__icontains=F('name'))
|
||||
.exists()
|
||||
|
|
|
@ -922,6 +922,18 @@ class TestDeniedName(TestCase):
|
|||
assert not DeniedName.blocked('IE6')
|
||||
assert not DeniedName.blocked('testo')
|
||||
|
||||
def test_blocked_emoji(self):
|
||||
assert not DeniedName.blocked('Test 🎧')
|
||||
assert not DeniedName.blocked('Test 🌠')
|
||||
|
||||
denied = DeniedName.objects.create(name='🌠')
|
||||
assert not DeniedName.blocked('Test 🎧')
|
||||
assert DeniedName.blocked('Test 🌠')
|
||||
|
||||
denied.update(name='🎧')
|
||||
assert DeniedName.blocked('Test 🎧')
|
||||
assert not DeniedName.blocked('Test 🌠')
|
||||
|
||||
|
||||
class TestIPNetworkUserRestriction(TestCase):
|
||||
def test_str(self):
|
||||
|
|
Загрузка…
Ссылка в новой задаче