1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +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

@@ -282,3 +282,17 @@ def test_filter_post_params(tmpdir, httpbin_both):
requests.post(url, data={'key': 'value'})
with vcr.use_cassette(cass_loc, filter_post_data_parameters=['key']) as cass:
assert b'key=value' not in cass.requests[0].body
def test_post_unicode_match_on_body(tmpdir, httpbin_both):
'''Ensure that matching on POST body that contains Unicode characters works.'''
data = {'key1': 'value1', '●‿●': '٩(●̮̮̃•̃)۶'}
url = httpbin_both + '/post'
with vcr.use_cassette(str(tmpdir.join('requests.yaml')), additional_matchers=('body',)):
req1 = requests.post(url, data).content
with vcr.use_cassette(str(tmpdir.join('requests.yaml')), additional_matchers=('body',)):
req2 = requests.post(url, data).content
assert req1 == req2