François Poulain 2020-08-05 16:52:53 +02:00 zatwierdzone przez Matt Westcott
rodzic c1da0fe56d
commit 0c6815910b
4 zmienionych plików z 25 dodań i 0 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ Changelog
* Serve PDFs inline in the browser (Matt Westcott)
* Make document `content-type` and `content-disposition` configurable via `WAGTAILDOCS_CONTENT_TYPES` and `WAGTAILDOCS_INLINE_CONTENT_TYPES` (Matt Westcott)
* Slug generation no longer removes stopwords (Andy Chosak, Scott Cranfill)
* Add check to disallow StreamField block names that do not match Python variable syntax (François Poulain)
* Fix: Make page-level actions accessible to keyboard users in page listing tables (Jesse Menn)
* Fix: `WAGTAILFRONTENDCACHE_LANGUAGES` was being interpreted incorrectly. It now accepts a list of strings, as documented (Karl Hobley)
* Fix: Update oEmbed endpoints to use https where available (Matt Westcott)

Wyświetl plik

@ -28,6 +28,7 @@ Other features
* Serve PDFs inline in the browser (Matt Westcott)
* Make document ``content-type`` and ``content-disposition`` configurable via ``WAGTAILDOCS_CONTENT_TYPES`` and ``WAGTAILDOCS_INLINE_CONTENT_TYPES`` (Matt Westcott)
* Slug generation no longer removes stopwords (Andy Chosak, Scott Cranfill)
* Add check to disallow StreamField block names that do not match Python variable syntax (François Poulain)
Bug fixes

Wyświetl plik

@ -1,4 +1,5 @@
import collections
import re
from importlib import import_module
from django import forms
@ -318,6 +319,16 @@ class Block(metaclass=BaseBlock):
id='wagtailcore.E001',
))
if not errors and not re.match(r'^[_a-zA-Z][_a-zA-Z0-9]*$', self.name):
errors.append(checks.Error(
"Block name %r is invalid" % self.name,
"Block names should follow standard Python conventions for "
"variable names: alpha-numeric and underscores, and cannot "
"begin with a digit",
obj=kwargs.get('field', self),
id='wagtailcore.E001',
))
return errors
def id_for_label(self, prefix):

Wyświetl plik

@ -3552,6 +3552,18 @@ class TestDateTimeBlock(TestCase):
class TestSystemCheck(TestCase):
def test_name_cannot_contain_non_alphanumeric(self):
block = blocks.StreamBlock([
('heading', blocks.CharBlock()),
('rich+text', blocks.RichTextBlock()),
])
errors = block.check()
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0].id, 'wagtailcore.E001')
self.assertEqual(errors[0].hint, "Block names should follow standard Python conventions for variable names: alpha-numeric and underscores, and cannot begin with a digit")
self.assertEqual(errors[0].obj, block.child_blocks['rich+text'])
def test_name_must_be_nonempty(self):
block = blocks.StreamBlock([
('heading', blocks.CharBlock()),