vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

replace_post_data_parameters does not correctly handle separators for multipart form data

Open tyewang opened this issue 5 years ago • 1 comments
trafficstars

replace_post_data_parameters always separates the key/value pairs based on &.

However, for multipart form data, the separator is defined by the boundary parameter in the Content-Type header, and we should not be splitting on &.

This bug leads to errors like this when trying to record requests that send multipart form data:

  File "/Users/tyewang/.virtualenvs/<redacted>/lib/python3.7/site-packages/vcr/filters.py", line 101, in replace_post_data_parameters                                            
    splits = [p.partition(b"=") for p in request.body.split(b"&")]                                                                                                                 
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xde in position 3: invalid continuation byte  

Here is the offending line - we should use the boundary parameter instead of & if available.

tyewang avatar Apr 21 '20 17:04 tyewang