Skip to content

html_attr escaping strategy #2615

@719media

Description

@719media

I've looked high and low for an answer to this, and I've come to ask for clarification.

I am using escape('html_attr') filter for something like, <div data-stuff="{{ thing|escape('html_attr') }}" >. When escaping large strings, this suffers from poor performance.

The best reasons I can find for using html_attr instead of html is:

  1. If you are not using quotes " to enclose your attribute (e.g. <div data-stuff=example>), then html_attr will work well because it will properly escapes spaces etc. I believe most people avoid this method because, well, it's ugly and horrible. But regardless, browsers do support it.
  2. If you are using old versions of IE, it will consider a tick mark ` to terminate the attribute, and html_attr will escape the ticks, avoiding this (e.g. it won't run into the problem of <div data-stuff="example`example">, which would cause <div data-stuff="example" example> in old IE)

Can you give me an example of a string which would give undesired outcome if escaped using only the default escape('html'), besides the above two scenarios? Thank you for your time.

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