summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-06-22 03:15:29 -0400
committerCarlton Gibson <carlton.gibson@noumenal.es>2018-06-22 09:33:05 +0200
commit8e082a6e0b63a1cfdb0bc7b2835c6447123aa239 (patch)
tree7472ce5625f414b8ac04f5c0610aedbd404975bf
parentcba1922742409661ad8328e9cb29628c56660976 (diff)
[2.0.x] Fixed #29511 -- Added charset to JavaScriptCatalog's Content-Type header.
Backport of 7cdeb23ae7ef2d125276840ff298dbb9683959f2 from master
-rw-r--r--django/views/i18n.py2
-rw-r--r--tests/view_tests/tests/test_i18n.py1
2 files changed, 2 insertions, 1 deletions
diff --git a/django/views/i18n.py b/django/views/i18n.py
index e121d3038a..240059a19f 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -311,7 +311,7 @@ class JavaScriptCatalog(View):
) if context['catalog'] else None
context['formats_str'] = indent(json.dumps(context['formats'], sort_keys=True, indent=2))
- return HttpResponse(template.render(Context(context)), 'text/javascript')
+ return HttpResponse(template.render(Context(context)), 'text/javascript; charset="utf-8"')
class JSONCatalog(JavaScriptCatalog):
diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py
index 38e5367d03..4f1a07b272 100644
--- a/tests/view_tests/tests/test_i18n.py
+++ b/tests/view_tests/tests/test_i18n.py
@@ -200,6 +200,7 @@ class I18NViewTests(SimpleTestCase):
catalog = gettext.translation('djangojs', locale_dir, [lang_code])
trans_txt = catalog.gettext('this is to be translated')
response = self.client.get('/jsi18n/')
+ self.assertEqual(response['Content-Type'], 'text/javascript; charset="utf-8"')
# response content must include a line like:
# "this is to be translated": <value of trans_txt Python variable>
# json.dumps() is used to be able to check unicode strings