Skip to content

Commit f4cfa34

Browse files
committed
Escape admin history delta changes
1 parent 38585bc commit f4cfa34

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

simple_history/admin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.template.defaultfilters import truncatechars
1313
from django.urls import re_path, reverse
1414
from django.utils.encoding import force_str
15-
from django.utils.html import mark_safe
15+
from django.utils.html import mark_safe, conditional_escape
1616
from django.utils.text import capfirst
1717
from django.utils.translation import gettext as _
1818

@@ -126,10 +126,12 @@ def format_history_delta_change(self, change: ModelChange) -> dict:
126126
the object history page.
127127
"""
128128
field_meta = self.model._meta.get_field(change.field)
129+
old = conditional_escape(change.old)
130+
new = conditional_escape(change.new)
129131
return {
130132
"field": capfirst(field_meta.verbose_name),
131-
"old": truncatechars(change.old, self.max_displayed_history_change_chars),
132-
"new": truncatechars(change.new, self.max_displayed_history_change_chars),
133+
"old": truncatechars(old, self.max_displayed_history_change_chars),
134+
"new": truncatechars(new, self.max_displayed_history_change_chars),
133135
}
134136

135137
def response_change(self, request, obj):

0 commit comments

Comments
 (0)