Serialize a value to JSON with HTML special characters escaped. This prevents injection when the JSON is embedded inside a tag.
(value: Any)
| 7 | |
| 8 | |
| 9 | def _html_safe_json(value: Any) -> str: |
| 10 | """Serialize a value to JSON with HTML special characters escaped. |
| 11 | |
| 12 | This prevents injection when the JSON is embedded inside a <script> tag. |
| 13 | """ |
| 14 | return ( |
| 15 | json.dumps(value) |
| 16 | .replace("<", "\\u003c") |
| 17 | .replace(">", "\\u003e") |
| 18 | .replace("&", "\\u0026") |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | swagger_ui_default_parameters: Annotated[ |
no test coverage detected
searching dependent graphs…