Skip to content

Translator should encode output again #100

Closed
@rvanlaak

Description

@rvanlaak

It seems that only when debug is enabled, TranslationExtension is used. The trans and transchoice filter then are marked as html safe, so the values will not get encoded anymore.

See https://github.com/php-translation/symfony-bundle/blob/master/Twig/TranslationExtension.php#L28-L29

As result of that, we "forget" to add {{ 'key'|trans|raw }}, because outputting raw values already happens on dev. When prod thereafter is updated, the encoded value just get outputted again:

So in Twig the following:

Translation value: This is a test that is valid until <strong>%date%</strong>
Twig: {{ 'translation_key'|trans({'%date%': date}) }}

Output on debug = true environments

This is a test that is valid until Wed June 14

Output on debug = false environments

This is a test that is valid until <strong>Wed June 14</strong>

We expect the output to be the same for any type of environment. The proposed solution would be to not handle is_safe via the Twig extensions. Are there any reasons why is_safe should be there?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions