Skip to content

Commit

Permalink
Revert "Fix for response with UTF-8 BOM #4976"
Browse files Browse the repository at this point in the history
This reverts commit 19cff44.
This reverts commit 9e27326.
This reverts commit f507a3e.
  • Loading branch information
nateprewitt authored and sethmlarson committed Feb 19, 2020
1 parent 24bcb9e commit fd13816
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 34 deletions.
3 changes: 0 additions & 3 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 0 additions & 30 deletions tests/test_testserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<doctype html><html><body>ジェーピーニック</body></html>'
)

with server as (host, port):
r = requests.get('http://{}:{}'.format(host, port))

assert r.status_code == 200
assert r.text == u'<doctype html><html><body>ジェーピーニック</body></html>'
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):
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit fd13816

Please sign in to comment.