Skip to content
Myr

Revert "Fix for response with UTF-8 BOM #4976"

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This reverts commit 19cff44ec1b8eeec99459b504a681aa440f6344c. This reverts commit 9e27326d6843e7c26e9847776159eeb68a999675. This reverts commit f507a3ef12ce6e100f68741f68d39bcaf8a70c7a.

authored by Nate Prewitt · committed by Seth Michael Larson · parent 24bcb9e · Browse files · 3 files+0 added−34 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+0 added−34 removed

  • tests:+0 added−31 removed
  • other:+0 added−3 removed

3 files+0 added−34 removed

modified:requests/models.py-3 removed
854 unmodified lines
855856 # Fallback to auto-detected encoding.857 if self.encoding is None:858 encoding = self.apparent_encoding859 # Forcefully remove BOM from UTF-8860 elif self.encoding.lower() == 'utf-8':861 encoding = 'utf-8-sig'859860 # Decode unicode from given encoding.861 try:862 content = str(self.content, encoding, errors='replace')
92 unmodified lines
modified:tests/test_testserver.py-30 removed
54 unmodified lines
55 assert r.status_code == 20056 assert r.text == u'roflol'57 assert r.headers['Content-Length'] == '6'5859 def test_text_bom_response(self):60 """the text_response_server sends the given text with UTF-8 BOM"""61 server = Server.text_response_server(62 "HTTP/1.1 200 OK\r\n" +63 "Content-Type: text/html; charset=UTF-8\r\n" +64 u'\r\n\ufeff<doctype html><html><body>ジェーピーニック</body></html>'65 )6667 with server as (host, port):68 r = requests.get('http://{}:{}'.format(host, port))6970 assert r.status_code == 20071 assert r.text == u'<doctype html><html><body>ジェーピーニック</body></html>'72 assert r.headers['Content-Type'] == 'text/html; charset=UTF-8'7374 def test_json_bom_response(self):75 """the text_response_server sends the given JSON with UTF-8 BOM"""76 server = Server.text_response_server(77 "HTTP/1.1 200 OK\r\n" +78 "Content-Type: application/json; charset=utf-8\r\n" +79 u'\r\n\ufeff{"success": true}'80 )8182 with server as (host, port):83 r = requests.get('http://{}:{}'.format(host, port))8485 assert r.status_code == 20086 assert r.json() == {'success': True}87 assert r.headers['Content-Type'] == 'application/json; charset=utf-8'8859 def test_basic_response(self):60 """the basic response server returns an empty http response"""61 with Server.basic_response_server() as (host, port):62 r = requests.get('http://{}:{}'.format(host, port))
104 unmodified lines
modified:tests/test_utils.py-1 removed
331 unmodified lines
332 assert guess_json_utf(b'\x00\x00\x00\x00') is None333334 @pytest.mark.parametrize(335 ('encoding', 'expected'), (336 ('utf-8-sig', 'utf-8-sig'),336 ('utf-16-be', 'utf-16'),337 ('utf-16-le', 'utf-16'),338 ('utf-32-be', 'utf-32'),339 ('utf-32-le', 'utf-32')
444 unmodified lines