Problem/Motivation
in #3379102: Add validation constraint to `type: label` + `type: text`: disallow control characters, a constraint that prevents adding special characters to a label has been added to label core schema. But plural_label (which inherits the label schema) contains, by design, at least one \x03 special character.
In core, there's only views.field.numeric:format_plural_string extending plural_label. In #3379102: Add validation constraint to `type: label` + `type: text`: disallow control characters, views.field.numeric:format_plural_string schema has been defined as:
format_plural_string:
type: plural_label
label: 'Plural variants'
constraints:
Regex:
# Normally, labels cannot contain invisible control characters. In this particular
# case, an invisible character (ASCII 3, 0x03) is used to encode translation
# information, so carve out an exception for that only.
# @see \Drupal\views\Plugin\views\field\NumericField
pattern: '/([^\PC\x03])/u'
match: false
message: 'Labels are not allowed to span multiple lines or contain control characters.'
But this is not quite correct, as all schemas extending plural_label should benefit from this relaxed constraint, not only views.field.numeric:format_plural_string.
I came to this in #2765065: Allow plurals on bundle labels, as suddenly teste started to fail.
Steps to reproduce
See #2765065: Allow plurals on bundle labels
Proposed resolution
Move the constraint from views.field.numeric:format_plural_string, upstream, in plural_label.
Question: Should we enforce at least one \x03 in plural_label?
As a side note, plural_label is semantically a sequence. Why is serialized as a string by concatenating the sequence items? A more correct fix is #2829919: Either avoid or explicitly test binary encoding in default configuration but that is too complex to be handled on short term. I think we should go with this for now.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
plural_label will get the correct constraint.
Release notes snippet
Issue fork drupal-3409588
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
claudiu.cristeaReady for review
Comment #4
claudiu.cristeaComment #5
claudiu.cristeaComment #6
claudiu.cristeaComment #7
wim leersYou're right. In the parent issue, we focused on
type: labeland just exempted this one exception (see https://git.drupalcode.org/project/drupal/-/merge_requests/4567/diffs?co...).I think we can generalize the scope of this issue though 🤓
We should expand the test coverage in
\Drupal\KernelTests\Core\Config\SimpleConfigValidationTest::testSpecialCharacters()(which was added in #3379102: Add validation constraint to `type: label` + `type: text`: disallow control characters).Comment #8
wim leersThis blocks #2765065: Allow plurals on bundle labels.
Comment #9
claudiu.cristeaComment #10
claudiu.cristeaTests added. Removing tag
Comment #11
claudiu.cristeaTests green. Ready for review.
Comment #12
smustgrave commentedShows the test coverage for the change.
The moving of the constraint makes sense to me.
Comment #13
alexpottLet's test the other side of this. That other characters result in an error. Plus it would be great if the test content looked a little more realistic that just the character.
Comment #14
claudiu.cristeaJust that the error message could be misleading because it might refer to
\x03Comment #15
dxvargas commentedThe MR here has conflicts after https://www.drupal.org/project/drupal/issues/3533926.
Adding this related issue here.
Comment #16
dxvargas commentedThe changes in the first commit of the MR here are the same as the changes already done in core after the MR in #3533926.
Like that, the only changes that we can keep here are the introduction of a test.
I'll adapt the title of this issue accordingly.
The new test is failing, so this still needs work.
Comment #17
dxvargas commentedThe test is fixed. It had an unrelated violation ( contains a translatable label, so a `langcode` is required, resulting in a violation of \Drupal\Core\Config\Plugin\Validation\Constraint\LangcodeRequiredIfTranslatableValuesConstraint).
Moving this issue to Needs review.
Comment #18
borisson_This looks good to me, this adds the needed test coverage.
Comment #19
claudiu.cristeaAlso, some credits, I think should be added in #3533926: Config of the type plural_label can never be valid due to the label constraint for the devs doing the initial code here, code that was the same as in #3533926: Config of the type plural_label can never be valid due to the label constraint (@wim leers, @smustgrave and me)
Comment #20
alexpott@claudiu.cristea I've creditted everyone on that issue.
Comment #21
alexpottCommitted a22092a and pushed to 11.x. Thanks!