Skip to content

[Validator] Regression to set false to htmlPattern in Regex constraint #57286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
elementaire opened this issue Jun 1, 2024 · 1 comment
Closed

Comments

@elementaire
Copy link
Contributor

Symfony version(s) affected

5.2, 5.3, 5.4, 6.0, 6.1, 6.2, 6.3, 6.4, 7.0, 7.1, 7.2

Description

When methods have been typed, we have lost the ability to set false to htmlPattern since symfony 5.2:

    public function __construct(
        $pattern,
        string $message = null,
        string $htmlPattern = null,
        bool $match = null,
        callable $normalizer = null,
        array $groups = null,
        $payload = null,
        array $options = []
    ) {

string|boolean|null is written in the documentation: https://symfony.com/doc/current/reference/constraints/Regex.html#htmlpattern

How to reproduce

#[Assert\Regex('/^FOO\d{5}$/', htmlPattern: false)]
private ?string $code = null;

Possible Solution

We need to fix:

  • type of parameter htmlPattern of method __construct() from ?string to string|bool|null
  • type of property htmlPattern from ?string to string|bool|null
  • revert modification in the method getHtmlPattern introduces in symfony/validator@4eed24f about useless empty instruction (or better, i guess, return null if htmlPattern is identical to false)

Additional Context

Workaround in FormType:

        $builder
            ->add('code', null, [
                'help' => 'Format: FOO00000',
                'attr' => [
                    'pattern' => false,
                ]
            ])
        ;
@elementaire
Copy link
Contributor Author

Duplicate #53807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants