Updated aiohappyeyeballs v2.4.4 -> v2.6.1 Updated aiosignal v1.3.1 -> v1.3.2 Updated filelock v3.16.1 -> v3.18.0 Updated frozenlist v1.5.0 -> v1.7.0 Updated markupsafe v2.0.1 -> v3.0.2 Updated mozilla-taskgraph v3.3.0 -> v3.3.1 Updated multidict v6.1.0 -> v6.4.4 Updated platformdirs v4.3.6 -> v4.3.8 Updated propcache v0.2.0 -> v0.3.2 Updated requests v2.32.3 -> v2.32.4 Updated types-python-dateutil v2.9.0.20241206 -> v2.9.0.20250516 Updated yarl v1.15.2 -> v1.20.1 Updated zipp v3.20.2 -> v3.23.0 Differential Revision: https://phabricator.services.mozilla.com/D249673
41 lines
1.3 KiB
Markdown
41 lines
1.3 KiB
Markdown
# MarkupSafe
|
|
|
|
MarkupSafe implements a text object that escapes characters so it is
|
|
safe to use in HTML and XML. Characters that have special meanings are
|
|
replaced so that they display as the actual characters. This mitigates
|
|
injection attacks, meaning untrusted user input can safely be displayed
|
|
on a page.
|
|
|
|
|
|
## Examples
|
|
|
|
```pycon
|
|
>>> from markupsafe import Markup, escape
|
|
|
|
>>> # escape replaces special characters and wraps in Markup
|
|
>>> escape("<script>alert(document.cookie);</script>")
|
|
Markup('<script>alert(document.cookie);</script>')
|
|
|
|
>>> # wrap in Markup to mark text "safe" and prevent escaping
|
|
>>> Markup("<strong>Hello</strong>")
|
|
Markup('<strong>hello</strong>')
|
|
|
|
>>> escape(Markup("<strong>Hello</strong>"))
|
|
Markup('<strong>hello</strong>')
|
|
|
|
>>> # Markup is a str subclass
|
|
>>> # methods and operators escape their arguments
|
|
>>> template = Markup("Hello <em>{name}</em>")
|
|
>>> template.format(name='"World"')
|
|
Markup('Hello <em>"World"</em>')
|
|
```
|
|
|
|
## Donate
|
|
|
|
The Pallets organization develops and supports MarkupSafe and other
|
|
popular packages. In order to grow the community of contributors and
|
|
users, and allow the maintainers to devote more time to the projects,
|
|
[please donate today][].
|
|
|
|
[please donate today]: https://palletsprojects.com/donate
|