Problem/Motivation

#3377030: Add validation constraint to `type: label`: disallow multiple lines added a basic constraint to type: label: disallowing multiple lines.

But … do we really want to allow any single-line string? 🤔 For example: do we want invisible control characters (think \x08 for "backspace": https://www.asciitable.com/) to be accepted?

Same thing for type: text, which is the multi-line sibling of type: label.

Steps to reproduce

N/A

Proposed resolution

  1. Disallow invisible control characters. PHP's regular expression library has a handy syntax for this: \PC. See https://stackoverflow.com/a/66587087.
  2. With the exception of:
    1. \n (*nix line endings, part of Windows line endings)
    2. \r (old macOS line endings, part of Windows line endings)
    3. \t (tabs, cannot be entered via the browser, but are harmless and could conceivably be added when modifying config outside a browser context)

Remaining tasks

TBD

User interface changes

None.

API changes

None.

Data model changes

Labels and text in config will be guaranteed to be both sensible and safe if the config has been validated: no invisible control characters present, besides \r, \n and \t.

Release notes snippet

None.

CommentFileSizeAuthor
#2 3379102-2.patch569 byteswim leers

Issue fork drupal-3379102

Command icon 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

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs work
StatusFileSize
new569 bytes

Here's a starting point!

wim leers’s picture

phenaproxima made their first commit to this issue’s fork.

phenaproxima’s picture

Assigned: Unassigned » wim leers
Status: Needs work » Needs review
Issue tags: -Needs tests

I'm guessing some tests will fail here, but in general I'm satisfied with this approach and I think we can start reviewing it.

wim leers’s picture

Assigned: wim leers » phenaproxima
Status: Needs review » Needs work
phenaproxima’s picture

Assigned: phenaproxima » wim leers
Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This is great, it a very simple improvement of the validation and it has solid test coverage. It's also great to see that not in core at least breaks this. I'm going to leave this assigned to Wim so he can give signoff as well, but at least from my side it's rtbc.

wim leers’s picture

Assigned: wim leers » phenaproxima
Status: Reviewed & tested by the community » Needs work

I requested a bit of extra test coverage, to ensure we don't disallow the ever-important emojis 😇

I agree that this looks great beyond that!

And I have one rather important question for y'all: should we disallow control characters in all strings by default? 🤔

borisson_’s picture

And I have one rather important question for y'all: should we disallow control characters in all strings by default? 🤔

I don't think so, I know that at least for Search API we have a configuration to control "whitespace characters", that contains \t\n\r by default.

wim leers’s picture

#11: sorry, #10 was not very clear. I think the default for type: string should be "no control characters allowed, except for \r and \n" (it is clearer on the GitLab merge request).

It's then up to individual projects to tweak the restrictions of type: string. Just like this MR is already doing for translatable strings.

While that should be the general rule (specific uses of type: string tweaking the validation constraint, and ideally defining their own type, because then it becomes a special kind of string!), I could see \t also being allowed by default, since it's A) safe, B) widely used.

That being said … maybe it's better to postpone this type: string stuff to a later time — type: label being stricter is a good step in the right direction, we can still move it up to that higher level in the inheritance chain later 😊

phenaproxima’s picture

Assigned: phenaproxima » wim leers
Status: Needs work » Needs review

Okay, added explicit test coverage of emoji!

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Reviewed & tested by the community

Looks great! 😄

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

Moving to NR to get the question on the MR answered

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

🏓

wim leers’s picture

Assigned: Unassigned » phenaproxima
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

@lauriii pointed out that \t is also reasonable to allow. Marking Needs work for that. Updated the issue summary too.

phenaproxima’s picture

Assigned: phenaproxima » wim leers
Status: Needs work » Needs review
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Reviewed & tested by the community

🤩 Love how little had to change — that shows how easy it is to evolve this, or copy/paste and tweak in other subtypes of type: string! 👍

phenaproxima’s picture

  • lauriii committed 3a661cf7 on 11.x
    Issue #3379102 by phenaproxima, Wim Leers, borisson_: Add validation...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3a661cf and pushed to 11.x. Thanks!

Wondering if we should create one central CR for the additional label + text constraints 🤔

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.