Skip to content

Bug: RegularExpressionValidator creates invalid regex in client-side #20322

Open
@Head0nF1re

Description

@Head0nF1re

Issue

In "yiisoft/yii2": "~2.0.45", the yii\validators\RegularExpressionValidator generates an invalid client-side regex for hexadecimal.

Given a pattern validation rule in a Form like ['foo', 'match', 'pattern' => '/^[\x00-\xFF]{8,72}$/'], the Html::escapeJsRegularExpression, inside the getClientOptions method, returns '/^[\u00-\uFF]{8,72}$/'. The former regex, which is valid in jquery 3.7.1 (seems to be the version being used by the framework), matches a word like "password" while the latter doesn't (because of the w in this case).

I believe this preg_replace in Html::escapeJsRegularExpression is the culprit:

$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $regexp);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions