From 1a67d2a72d0587ce936dfaa87ed1c02e1b4dc68f Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 30 Jul 2014 01:35:47 +0200 Subject: [PATCH] Use application/javascript instead of application/x-javascript for the Content-Type http header of JavaScript resources. Also see: http://stackoverflow.com/questions/9664282 --- CHANGES.rst | 7 ++- .../tests/testJSRegistry.py | 44 +++++++++---------- .../ResourceRegistries/tools/JSRegistry.py | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index faad10d..f7cebbf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,12 @@ Changelog 3.0.1 (unreleased) ------------------ -- bugfix: do not convert URIs such as +- Use ``application/javascript`` instead of ``application/x-javascript`` for + the ``Content-Type`` http header of JavaScript resources. Also see: + http://stackoverflow.com/questions/9664282 + [thet] + +- bugfix: do not convert URIs such as url(data:image/svg+xml;base64,PD94bWwgdmVyc2lv) to absolute urls see https://github.com/plone/Products.ResourceRegistries/pull/16 [cillianderoiste] diff --git a/Products/ResourceRegistries/tests/testJSRegistry.py b/Products/ResourceRegistries/tests/testJSRegistry.py index 296cffa..eaa3583 100644 --- a/Products/ResourceRegistries/tests/testJSRegistry.py +++ b/Products/ResourceRegistries/tests/testJSRegistry.py @@ -453,7 +453,7 @@ def afterSetUp(self): def testPublishJSThroughTool(self): response = self.publish(self.toolpath + '/test_rr_1.js') self.assertEqual(response.getStatus(), 200) - self.assertEqual(response.getHeader('Content-Type'), 'application/x-javascript;charset=utf-8') + self.assertEqual(response.getHeader('Content-Type'), 'application/javascript; charset=utf-8') def testPublishNonMagicJSThroughTool(self): self.setRoles(['Manager']) @@ -462,7 +462,7 @@ def testPublishNonMagicJSThroughTool(self): self.tool.registerScript('testmethod') response = self.publish(self.toolpath + '/testmethod') self.assertEqual(response.getStatus(), 200) - self.assertEqual(response.getHeader('Content-Type'), 'application/x-javascript;charset=utf-8') + self.assertEqual(response.getHeader('Content-Type'), 'application/javascript; charset=utf-8') def testPublishPageWithInlineJS(self): # This one fails from string/utf-8 concatenation @@ -576,14 +576,14 @@ def afterSetUp(self): self.setRoles(['Manager']) self.portal.invokeFactory('File', id='testroot.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('red')") self.portal.invokeFactory('Folder', 'subfolder') self.portal.subfolder.invokeFactory('File', id='testsubfolder.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('blue')") self.tool.registerScript('testroot.js') @@ -627,13 +627,13 @@ def testContextDependantInlineJS(self): self.portal.invokeFactory('Folder', 'folder2') self.portal.folder1.invokeFactory('File', id='context.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('pink')") self.portal.folder2.invokeFactory('File', id='context.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('purple')") self.tool.registerScript('context.js', inline=True) self.setRoles(['Member']) @@ -661,8 +661,8 @@ def afterSetUp(self): self.setRoles(['Manager']) self.portal.invokeFactory('File', id='testroot.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('red')") script = self.portal.restrictedTraverse('testroot.js') @@ -758,13 +758,13 @@ def afterSetUp(self): self.setRoles(['Manager']) self.portal.invokeFactory('File', id='testroot.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('green')") self.portal.invokeFactory('File', id='simple2.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('blue')") self.setRoles(['Member']) self.tool.setDebugMode(False) @@ -846,13 +846,13 @@ def testLargerCompositionWithMiddleUncooked(self): self.setRoles(['Manager']) self.portal.invokeFactory('File', id='testpurple.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('purple')") self.portal.invokeFactory('File', id='testpink.js', - format='application/x-javascript', - content_type='application/x-javascript', + format='application/javascript', + content_type='application/javascript', file="window.alert('pink')") self.setRoles(['Member']) self.tool.registerScript('testpurple.js') @@ -895,8 +895,8 @@ def afterSetUp(self): self.portal.addDTMLMethod('testmethod.js', file=body) self.portal.invokeFactory('File', id='testfile.js', - format='application/x-javascript', - content_type='application/x-javascript;charset=utf-8', + format='application/javascript', + content_type='application/javascript; charset=utf-8', file=body) self.setRoles(['Member']) self.tool.setDebugMode(False) diff --git a/Products/ResourceRegistries/tools/JSRegistry.py b/Products/ResourceRegistries/tools/JSRegistry.py index 5a99f4c..3f881ea 100644 --- a/Products/ResourceRegistries/tools/JSRegistry.py +++ b/Products/ResourceRegistries/tools/JSRegistry.py @@ -252,7 +252,7 @@ def getExternalCompressionOptions(self): security.declareProtected(permissions.View, 'getContentType') def getContentType(self): """Return the registry content type.""" - return 'application/x-javascript;charset=utf-8' + return 'application/javascript; charset=utf-8' security.declarePrivate('getResourceContent') def getResourceContent(self, item, context, original=False, theme=None):