Add validation constraint to type: plural_label; remove work-around from views.field.numeric:format_plural_string

Created on 18 December 2023, about 1 year ago
Updated 29 March 2024, 9 months ago

Problem/Motivation

in πŸ“Œ Add validation constraint to `type: label` + `type: text`: disallow control characters Fixed , 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 πŸ“Œ Add validation constraint to `type: label` + `type: text`: disallow control characters Fixed , 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 ✨ [PP-1] Allow plurals on bundle labels Postponed , as suddenly teste started to fail.

Steps to reproduce

See ✨ [PP-1] Allow plurals on bundle labels Postponed

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 πŸ“Œ Either avoid or explicitly test binary encoding in default configuration Needs work 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

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
ConfigurationΒ  β†’

Last updated 2 days ago

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024