From b42f3de3577f754c76c5a8afb0d93d632cc1e439 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Jan 2024 10:51:23 +1100 Subject: [PATCH] Bug fix for javascript rendering (#6362) * Check template name when rendering also * Update i18n.py Enforce stringiness --- InvenTree/InvenTree/templatetags/i18n.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/templatetags/i18n.py b/InvenTree/InvenTree/templatetags/i18n.py index fffaa352c2..6aaa7213a6 100644 --- a/InvenTree/InvenTree/templatetags/i18n.py +++ b/InvenTree/InvenTree/templatetags/i18n.py @@ -52,7 +52,18 @@ class CustomTranslateNode(TranslateNode): # Escape any quotes contained in the string, if the request is for a javascript file request = context.get('request', None) - if self.escape or (request and request.path.endswith('.js')): + template = getattr(context, 'template_name', None) + request = context.get('request', None) + + escape = self.escape + + if template and str(template).endswith('.js'): + escape = True + + if request and str(request.path).endswith('.js'): + escape = True + + if escape: result = result.replace("'", r'\'') result = result.replace('"', r'\"')