Skip to content

BaseHtml::escapeJsRegularExpression() fails with non-slash delimiters and complex patterns #20456

@santilin

Description

@santilin

The function yii\helpers\BaseHtml::escapeJsRegularExpression() fails to process valid regular expressions when the delimiter is not /. For example, it fails with this input:

([a-z_])([a-z0-9_])*

Expected output:

/([a-z_])([a-z0-9_])*/

Actual output:

/[a-z_])/

The function truncates the input because it assumes the first character is a delimiter and tries to find the last occurrence of it to extract the pattern. This breaks when the pattern contains the first character in the middle of the pattern.

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