Skip to content

Commit 6c92a65

Browse files
committed
escaped some text
1 parent 03e05bc commit 6c92a65

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

easyaudit/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core.urlresolvers import reverse
77

88
from django.utils.safestring import mark_safe
9+
from django.utils.html import escape
910
from . import settings
1011
from .models import CRUDEvent, LoginEvent, RequestEvent
1112
from .admin_helpers import prettify_json, EasyAuditModelAdmin
@@ -28,13 +29,14 @@ def object_repr_link(self, obj):
2829
html = obj.object_repr
2930
else:
3031
try:
32+
escaped_obj_repr = escape(obj.object_repr)
3133
url = reverse("admin:%s_%s_change" % (
3234
obj.content_type.app_label,
3335
obj.content_type.model,
3436
), args=(obj.object_id,))
35-
html = '<a href="%s">%s</a>' % (url, obj.object_repr)
37+
html = '<a href="%s">%s</a>' % (url, escaped_obj_repr)
3638
except:
37-
html = obj.object_repr
39+
html = escape(obj.object_repr)
3840
return mark_safe(html)
3941

4042
object_repr_link.short_description = 'object repr'

easyaudit/admin_helpers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@
1313
from django.contrib import messages
1414
from django.conf.urls import url
1515
from django.utils.safestring import mark_safe
16+
from django.utils.html import escape
1617
from . import settings
1718

1819
import json
1920

20-
2121
def prettify_json(json_string):
2222
"""Given a JSON string, it returns it as a
2323
safe formatted HTML"""
24+
escaped = escape(json_string)
2425
try:
25-
data = json.loads(json_string)
26-
html = '<pre>' + json.dumps(data, sort_keys=True, indent=4) + '</pre>'
26+
data = json.loads(escaped)
27+
# html = '<pre>' + json.dumps(data, sort_keys=True, indent=4) + '</pre>'
28+
html = json.dumps(data, sort_keys=True, indent=4)
2729
except:
28-
html = json_string
29-
return mark_safe(html)
30+
html = escaped
31+
return html
3032

3133

3234
class EasyAuditModelAdmin(admin.ModelAdmin):
@@ -38,13 +40,14 @@ def user_link(self, obj):
3840
return '-'
3941
try:
4042
user_model = get_user_model()
43+
escaped = escape(str(user))
4144
url = reverse("admin:%s_%s_change" % (
4245
user_model._meta.app_label,
4346
user_model._meta.model_name,
4447
), args=(user.id,))
45-
html = '<a href="%s">%s</a>' % (url, str(user))
48+
html = '<a href="%s">%s</a>' % (url, escaped)
4649
except:
47-
html = str(user)
50+
html = escape(str(user))
4851
return mark_safe(html)
4952
user_link.short_description = 'user'
5053

0 commit comments

Comments
 (0)