kopia lustrzana https://github.com/wagtail/wagtail
Stronger check on blocks names (#6295)
Ref: https://github.com/wagtail/wagtail-react-streamfield/issues/54pull/6414/head
rodzic
c1da0fe56d
commit
0c6815910b
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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()),
|
||||
|
|
Ładowanie…
Reference in New Issue