Skip to content

Commit 9b9f5f5

Browse files
Merge pull request #17 from diegojromerolopez/fix-safe_value-issue
Fix save_value issue
2 parents efac086 + 7e615b2 commit 9b9f5f5

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
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.9
5+
-------------
6+
* Fix: fix passing simple values (strings or numbers) as parameters.
7+
48
Version 0.6.8
59
-------------
610
* Feature: "onload" parameter for the async_include template_tag, allowing calling a callback function.

async_include/crypto.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
from Crypto.Cipher import AES
66

77

8-
def encrypt(key, data):
8+
def encrypt(key: str, text: str):
99
cipher = AES.new(key.encode('utf-8'), AES.MODE_EAX)
10-
encrypted_data, tag = cipher.encrypt_and_digest(data.encode('utf-8'))
10+
encrypted_data, tag = cipher.encrypt_and_digest(text.encode('utf-8'))
1111
return cipher.nonce, encrypted_data, tag
1212

1313

14-
def decrypt(key, nonce, encrypted_data, tag):
14+
def decrypt(key: str, nonce: str, encrypted_data: str, tag: str):
1515
cipher = AES.new(
16-
key.encode('utf-8'), AES.MODE_EAX, nonce.encode('latin-1')
16+
key.encode('utf-8'), AES.MODE_EAX, nonce.encode('utf-8')
1717
)
1818
data = cipher.decrypt_and_verify(
19-
encrypted_data.encode('latin-1'), tag.encode('latin-1')
19+
encrypted_data.encode('utf-8'), tag.encode('utf-8')
2020
)
2121
return data.decode('utf-8')

async_include/templatetags/async_include.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def async_include(context, template_path, *args, **kwargs):
126126
sql_query, params = context_object.query.sql_with_params()
127127

128128
nonce, encrypted_sql, tag = crypto.encrypt(
129-
key=settings.SECRET_KEY[:16], data=sql_query
129+
key=settings.SECRET_KEY[:16], text=sql_query
130130
)
131131

132132
replacements['context'][context_object_name] = {
@@ -142,7 +142,10 @@ def async_include(context, template_path, *args, **kwargs):
142142
# Safe values are sent as is to the view
143143
# that will render the template
144144
else:
145-
context_object_as_str = '{0}'.format(context_object)
145+
if isinstance(context_object, str):
146+
context_object_as_str = context_object
147+
else:
148+
context_object_as_str = '{0}'.format(context_object)
146149
replacements['context'][context_object_name] = {
147150
'type': 'safe_value',
148151
'value': context_object,

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_as_str)
104+
checksum.make(value)
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.8",
23+
version="0.6.9",
2424
author="Diego J. Romero López",
2525
author_email="[email protected]",
2626
description=(

0 commit comments

Comments
 (0)