From 399e32075d6ddacd2c052c48627db6fa01f5bd46 Mon Sep 17 00:00:00 2001 From: Archmonger <16909269+Archmonger@users.noreply.github.com> Date: Mon, 29 Jan 2024 01:02:55 -0800 Subject: [PATCH] Test whether HTML objects and strings are escaped --- tests/test_app/components.py | 14 ++++++++++++++ tests/test_app/templates/base.html | 2 ++ tests/test_app/views.py | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_app/components.py b/tests/test_app/components.py index dbe9bd8f..f473f60e 100644 --- a/tests/test_app/components.py +++ b/tests/test_app/components.py @@ -71,6 +71,20 @@ def object_in_templatetag(my_object: TestObject): ) +@component +def html_in_templatetag(my_html_object: str, my_string: str): + success = ( + my_html_object == "
Hello World
" + and my_string == "
Hello World
" + ) + co_name = inspect.currentframe().f_code.co_name # type: ignore + return html._( + html.div( + {"id": co_name, "data-success": success}, f"{co_name}: ", my_html_object + ) + ) + + SimpleButtonModule = web.module_from_file( "SimpleButton", Path(__file__).parent / "tests" / "js" / "simple-button.js", diff --git a/tests/test_app/templates/base.html b/tests/test_app/templates/base.html index f15094ac..b1543b5a 100644 --- a/tests/test_app/templates/base.html +++ b/tests/test_app/templates/base.html @@ -27,6 +27,8 @@

ReactPy Test Page


{% component "test_app.components.object_in_templatetag" my_object %}
+ {% component "test_app.components.html_in_templatetag" my_html_object "
Hello World
" %} +
{% component "test_app.components.simple_button" %}
{% component "test_app.components.use_connection" %} diff --git a/tests/test_app/views.py b/tests/test_app/views.py index 7af05f61..926be583 100644 --- a/tests/test_app/views.py +++ b/tests/test_app/views.py @@ -10,7 +10,11 @@ def base_template(request): - return render(request, "base.html", {"my_object": TestObject(1)}) + return render( + request, + "base.html", + {"my_object": TestObject(1), "my_html_object": "
Hello World
"}, + ) def errors_template(request):