Skip to content

html_attr docs are misleading / unclear #2817

@timglabisch

Description

@timglabisch

i had a discussion with some of my co workers about escaping strategies and when to use 'html_attr'.

from my point of view, we should add an example when to use html_attr instead of html.

The docs are saying that:

html: escapes a string for the HTML body context.
html_attr: escapes a string for the HTML attribute context.

example 1

following the docs, this wouldn't be best practice, but it seems to be "fine".
#2615 (comment)

{% set untrusted = 'untrusted' %}
<div class="{{ untrusted }}">{{ untrusted }}</a>

example 2

if you stick to the docs this should be best practice?

{% set untrusted = 'untrusted' %}
<div class="{{ untrusted | e('html_attr') }}">{{ untrusted }}</a>

is there any reason why example1 is wrong?

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