Skip to content

Backreferences (\0) from preg_replace cause unwanted behavior #7

@psn-media

Description

@psn-media

Hello everyone.

When using “\0” in content (body), the preg_replace function inserts the entire content (body) back at this point. In some cases, this can lead to the problem that the body is inserted again at a point in the body. This results in nesting within the website.

If you also think this is a problem you could use preg_replace_callback instead of preg_replace in function setBody.
(vendor/in2code/in2glossar/Classes/EventListener/ContentPostProcessor.php)

You could replace

protected function setBody(string $body): void
{
    $this->tsfe->content = preg_replace(
        '/(<body[^>]*>)(.*)(<\/body>)/Uims',
        '$1' . $body . '$3',
        $this->tsfe->content,
    );
}

with

protected function setBody(string $body): void
{
    $this->tsfe->content = preg_replace_callback(
        '/(<body[^>]*>)(.*)(<\/body>)/Uims',
        function ($matches) use ($body) {
            return $matches[1] . $body . $matches[3];
        },
        $this->tsfe->content
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions