Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test whether HTML objects and strings are escaped #219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test_app/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "<div> Hello World </div>"
and my_string == "<div> Hello World </div>"
)
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",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ <h1>ReactPy Test Page</h1>
<hr>
{% component "test_app.components.object_in_templatetag" my_object %}
<hr>
{% component "test_app.components.html_in_templatetag" my_html_object "<div> Hello World </div>" %}
<hr>
{% component "test_app.components.simple_button" %}
<hr>
{% component "test_app.components.use_connection" %}
Expand Down
6 changes: 5 additions & 1 deletion tests/test_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<div> Hello World </div>"},
)


def errors_template(request):
Expand Down
Loading