Commit 3091dbb2 authored by Jérome Perrin's avatar Jérome Perrin

erp5: 🚧 try zope patch 🚧

parent 2312ed83
Pipeline #25161 failed with stage
in 0 seconds
From 346f895cd6c95346bcd8668fd7e7a90e9547e789 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 22 Nov 2022 17:33:02 +0900
Subject: [PATCH] HTTPResponse: default content type to text/plain
---
src/ZPublisher/HTTPResponse.py | 11 +++++------
src/ZPublisher/tests/testHTTPResponse.py | 8 ++++----
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/ZPublisher/HTTPResponse.py b/src/ZPublisher/HTTPResponse.py
index 002737d15..b9337201c 100644
--- a/src/ZPublisher/HTTPResponse.py
+++ b/src/ZPublisher/HTTPResponse.py
@@ -462,9 +462,13 @@ class HTTPResponse(BaseResponse):
if isinstance(body, tuple) and len(body) == 2:
title, body = body
+ content_type = self.headers.get('content-type')
+
if not isinstance(body, str):
if hasattr(body,'asHTML'):
body = body.asHTML()
+ if content_type is None:
+ content_type = 'text/html'
if isinstance(body, unicode):
body = self._encode_unicode(body)
@@ -491,8 +495,6 @@ class HTTPResponse(BaseResponse):
self.body = body
- content_type = self.headers.get('content-type')
-
# Some browsers interpret certain characters in Latin 1 as html
# special characters. These cannot be removed by html_quote,
# because this is not the case for all encodings.
@@ -503,10 +505,7 @@ class HTTPResponse(BaseResponse):
self.body = body
if content_type is None:
- if self.isHTML(self.body):
- content_type = 'text/html; charset=%s' % default_encoding
- else:
- content_type = 'text/plain; charset=%s' % default_encoding
+ content_type = 'text/plain; charset=%s' % default_encoding
self.setHeader('content-type', content_type)
else:
if (content_type.startswith('text/') and
diff --git a/src/ZPublisher/tests/testHTTPResponse.py b/src/ZPublisher/tests/testHTTPResponse.py
index 42946973a..9bbc932af 100644
--- a/src/ZPublisher/tests/testHTTPResponse.py
+++ b/src/ZPublisher/tests/testHTTPResponse.py
@@ -584,7 +584,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result)
self.assertEqual(response.body, EXPECTED)
self.assertEqual(response.getHeader('Content-Type'),
- 'text/html; charset=iso-8859-15')
+ 'text/plain; charset=iso-8859-15')
self.assertEqual(response.getHeader('Content-Length'),
str(len(EXPECTED)))
@@ -598,7 +598,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue('TITLE' in response.body)
self.assertTrue('BODY' in response.body)
self.assertEqual(response.getHeader('Content-Type'),
- 'text/html; charset=iso-8859-15')
+ 'text/plain; charset=iso-8859-15')
def test_setBody_string_not_HTML(self):
response = self._makeOne()
@@ -616,7 +616,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result)
self.assertEqual(response.body, HTML)
self.assertEqual(response.getHeader('Content-Type'),
- 'text/html; charset=iso-8859-15')
+ 'text/plain; charset=iso-8859-15')
self.assertEqual(response.getHeader('Content-Length'), str(len(HTML)))
def test_setBody_object_with_asHTML(self):
@@ -640,7 +640,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result)
self.assertEqual(response.body, ENCODED)
self.assertEqual(response.getHeader('Content-Type'),
- 'text/html; charset=iso-8859-15')
+ 'text/plain; charset=iso-8859-15')
self.assertEqual(response.getHeader('Content-Length'),
str(len(ENCODED)))
--
2.37.0
......@@ -696,6 +696,8 @@ Acquisition-patches = ${:_profile_base_location_}/../../component/egg-patch/Acqu
Acquisition-patch-options = -p1
python-magic-patches = ${:_profile_base_location_}/../../component/egg-patch/python_magic/magic.patch#de0839bffac17801e39b60873a6c2068
python-magic-patch-options = -p1
Zope2-patches = ${:_profile_base_location_}/../../component/egg-patch/Zope2/0001-HTTPResponse-default-content-type-to-text-plain.patch#7d6a62aedc7756a053004521fbf6d644
Zope2-patch-options = -p1
# neoppod installs bin/coverage so we inject erp5 plugin here so that coverage script can use it in report
......@@ -739,7 +741,7 @@ PyPDF2 = 1.26.0+SlapOSPatched001
pylint = 1.4.4+SlapOSPatched002
# astroid 1.4.1 breaks testDynamicClassGeneration
astroid = 1.3.8+SlapOSPatched001
Zope2 = 2.13.30+SlapOSPatched001
# use newer version than specified in ZTK
PasteDeploy = 1.5.2
argparse = 1.4.0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment