From fd13816d015c4c90ee65297fa996caea6a094ed1 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Tue, 18 Feb 2020 15:01:34 -0800 Subject: [PATCH] Revert "Fix for response with UTF-8 BOM #4976" This reverts commit 19cff44ec1b8eeec99459b504a681aa440f6344c. This reverts commit 9e27326d6843e7c26e9847776159eeb68a999675. This reverts commit f507a3ef12ce6e100f68741f68d39bcaf8a70c7a. --- requests/models.py | 3 --- tests/test_testserver.py | 30 ------------------------------ tests/test_utils.py | 1 - 3 files changed, 34 deletions(-) diff --git a/requests/models.py b/requests/models.py index edd162400d..357988327e 100644 --- a/requests/models.py +++ b/requests/models.py @@ -856,9 +856,6 @@ def text(self): # Fallback to auto-detected encoding. if self.encoding is None: encoding = self.apparent_encoding - # Forcefully remove BOM from UTF-8 - elif self.encoding.lower() == 'utf-8': - encoding = 'utf-8-sig' # Decode unicode from given encoding. try: diff --git a/tests/test_testserver.py b/tests/test_testserver.py index 9d9def2f1b..aac529261b 100644 --- a/tests/test_testserver.py +++ b/tests/test_testserver.py @@ -56,36 +56,6 @@ def test_text_response(self): assert r.text == u'roflol' assert r.headers['Content-Length'] == '6' - def test_text_bom_response(self): - """the text_response_server sends the given text with UTF-8 BOM""" - server = Server.text_response_server( - "HTTP/1.1 200 OK\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n" + - u'\r\n\ufeffジェーピーニック' - ) - - with server as (host, port): - r = requests.get('http://{}:{}'.format(host, port)) - - assert r.status_code == 200 - assert r.text == u'ジェーピーニック' - assert r.headers['Content-Type'] == 'text/html; charset=UTF-8' - - def test_json_bom_response(self): - """the text_response_server sends the given JSON with UTF-8 BOM""" - server = Server.text_response_server( - "HTTP/1.1 200 OK\r\n" + - "Content-Type: application/json; charset=utf-8\r\n" + - u'\r\n\ufeff{"success": true}' - ) - - with server as (host, port): - r = requests.get('http://{}:{}'.format(host, port)) - - assert r.status_code == 200 - assert r.json() == {'success': True} - assert r.headers['Content-Type'] == 'application/json; charset=utf-8' - def test_basic_response(self): """the basic response server returns an empty http response""" with Server.basic_response_server() as (host, port): diff --git a/tests/test_utils.py b/tests/test_utils.py index ae51770556..463516b2e5 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -333,7 +333,6 @@ def test_bad_utf_like_encoding(self): @pytest.mark.parametrize( ('encoding', 'expected'), ( - ('utf-8-sig', 'utf-8-sig'), ('utf-16-be', 'utf-16'), ('utf-16-le', 'utf-16'), ('utf-32-be', 'utf-32'),