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.
@@ -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),
)
