Skip to content

add preg_quote_replacement() function #9663

Open
@tomasfejfar

Description

@tomasfejfar

Description

$pattern = '/[[name]]/';
$template = 'My name is [[name]]';
preg_replace($pattern, $_POST['name'], $template);

This is prone to injection of any match from the pattern if user supplies for example Tomas$1Fejfar. There is a preg_quote function that can be used to escape special chars in template. There should be same function that would escape the replacement.

preg_quote_replacement($_POST['name']); // Tomas\$1Fejfar

IMHO it is enough to escape backslash and dollars with backslash, but I am not sure.

Currently the replacement must be escaped using userland function that makes it prone to mistakes.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions