Skip to content

Escaping #5

@pelme

Description

@pelme

Thanks for a very interesting and useful library!

Currently, no escaping children or attributes of inputs is done. This makes the library unsafe for general purpose use IMO.

>>> print(div('<script>alert("danger!")</script>'))
<div><script>alert("danger!")</script></div>
>>> print(div(id='">hello'))
<div id="">hello"></div>

I think all input strings should be escaped by default (python has html.escape: https://docs.python.org/3/library/html.html

Django has a concept of safe strings where all inputs to templates are escaped by default. When you want to inject trusted HTML, you mark the string as safe with mark_safe:
https://docs.djangoproject.com/en/4.2/_modules/django/utils/safestring/

The convention is basically that an object with a __html__() will not be escaped.

Would you be open to add escaping or accept a PR that implements it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions