1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

Fix matching on 'body' failing when Unicode symbols are present in them

Matching on bodies uses urllib.parse.parse_qs(), which fails to handle
UTF-8+URLEncoded POST bodies when the input is `bytes` rather than `str`,
causing matching to fail..
Fixed this by always doing decode('ascii') on URLEncoded POST bodies first.
This commit is contained in:
Martin Valgur
2018-09-06 19:18:28 +03:00
parent 895850b197
commit 302ea35d9a
2 changed files with 20 additions and 3 deletions

View File

@@ -56,9 +56,12 @@ def _transform_json(body):
_xml_header_checker = _header_checker('text/xml')
_xmlrpc_header_checker = _header_checker('xmlrpc', header='User-Agent')
_checker_transformer_pairs = (
(_header_checker('application/x-www-form-urlencoded'), urllib.parse.parse_qs),
(_header_checker('application/json'), _transform_json),
(lambda request: _xml_header_checker(request) and _xmlrpc_header_checker(request), xmlrpc_client.loads),
(_header_checker('application/x-www-form-urlencoded'),
lambda body: urllib.parse.parse_qs(body.decode('ascii'))),
(_header_checker('application/json'),
_transform_json),
(lambda request: _xml_header_checker(request) and _xmlrpc_header_checker(request),
xmlrpc_client.loads),
)