Skip to content

Commit fb478af

Browse files
Fix safe strings as parameters in async_include template tag
1 parent 9b9f5f5 commit fb478af

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes
22
=======
33

4+
Version 0.6.10
5+
-------------
6+
* Fix: safe strings can be used as parameters of the async_include template tag.
7+
48
Version 0.6.9
59
-------------
610
* Fix: fix passing simple values (strings or numbers) as parameters.

async_include/templatetags/async_include.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import jsonpickle
66
import uuid
77

8+
from django.utils.safestring import SafeString
9+
810
from .. import crypto
911
from .. import checksum
1012

@@ -139,6 +141,16 @@ def async_include(context, template_path, *args, **kwargs):
139141
'model': model_name,
140142
}
141143

144+
# Safe strings are converted to strings
145+
elif isinstance(context_object, SafeString):
146+
context_object_as_str = str.__str__(context_object)
147+
replacements['context'][context_object_name] = {
148+
'type': 'safe_value',
149+
'value': context_object_as_str,
150+
'value_as_str': context_object_as_str,
151+
'__checksum__': checksum.make(context_object_as_str)
152+
}
153+
142154
# Safe values are sent as is to the view
143155
# that will render the template
144156
else:

async_include/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_template(request):
101101
# Checking if JSON has been tampered
102102
if (
103103
context_object_load_params['__checksum__'] !=
104-
checksum.make(value)
104+
checksum.make(value_as_str)
105105
):
106106
return HttpResponse(
107107
status=403,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name="django-async-include",
23-
version="0.6.9",
23+
version="0.6.10",
2424
author="Diego J. Romero López",
2525
author_email="[email protected]",
2626
description=(

0 commit comments

Comments
 (0)