Skip to content

Commit

Permalink
Escape admin history delta changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Feb 18, 2024
1 parent 38585bc commit f4cfa34
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.template.defaultfilters import truncatechars
from django.urls import re_path, reverse
from django.utils.encoding import force_str
from django.utils.html import mark_safe
from django.utils.html import mark_safe, conditional_escape
from django.utils.text import capfirst
from django.utils.translation import gettext as _

Expand Down Expand Up @@ -126,10 +126,12 @@ def format_history_delta_change(self, change: ModelChange) -> dict:
the object history page.
"""
field_meta = self.model._meta.get_field(change.field)
old = conditional_escape(change.old)
new = conditional_escape(change.new)
return {
"field": capfirst(field_meta.verbose_name),
"old": truncatechars(change.old, self.max_displayed_history_change_chars),
"new": truncatechars(change.new, self.max_displayed_history_change_chars),
"old": truncatechars(old, self.max_displayed_history_change_chars),
"new": truncatechars(new, self.max_displayed_history_change_chars),
}

def response_change(self, request, obj):
Expand Down

0 comments on commit f4cfa34

Please sign in to comment.