Bug fix for javascript rendering (#6362)

* Check template name when rendering also

* Update i18n.py

Enforce stringiness
This commit is contained in:
Oliver 2024-01-30 10:51:23 +11:00 committed by GitHub
parent b29d86403e
commit b42f3de357
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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'\"')