-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
html_attr escaping strategy #2615
Copy link
Copy link
Closed
Description
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:
- 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. - 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels