Ver código fonte

Fixed #29511 -- Added charset to JavaScriptCatalog's Content-Type header.

Tim Graham 6 anos atrás
pai
commit
7cdeb23ae7
2 arquivos alterados com 2 adições e 1 exclusões
  1. 1 1
      django/views/i18n.py
  2. 1 0
      tests/view_tests/tests/test_i18n.py

+ 1 - 1
django/views/i18n.py

@@ -284,7 +284,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):

+ 1 - 0
tests/view_tests/tests/test_i18n.py

@@ -206,6 +206,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