-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form-Data not treated as binary when request is intercepted #20143
Comments
Thanks for the report, and for opening a pull request! We'll get a second reviewer from the team here in the next few days, and try to get it merged in time for the next release (currently planned as 9.5.1). |
@mlauinger Merging #20144 revealed some unintended breakage in The patch to In light of this, we're going to revert #20144 for the time being, and look for another solution. The main issue here seems to be our use of
This has the end effect of making the types of I think that it would make sense to do 2 things here to fix this behavior:
Additionally, a future improvement to Thoughts @mlauinger @BlueWinds ? |
I think this all sounds very reasonable. I was noticing
This seems less important, as you said, and I'm not sure adding an additional library is necessary on our end. Something to consider for a later date. |
Meanwhile, what would be the current way to mock Doesn't seem to work atm: const formData = new FormData();
formData.append('some', 'text');
cy.intercept('some-api', formData); |
Still the Issue persist in 12.17.1V as well. Can somebody help and fix this issue ? |
Just encountered this in v13.7.3 |
Ah, this would work, slightly cleaner than our current approach which is to just check if the |
Also facing an issue with this v13.8.1. We are uploading a file via a multipart/form-data request with other fields and the cy.intercept() we need to use is corrupting the file. In DevTools we're seeing characters like 'ÿ' replaced with '�' and the server-side processing is failing to parse correctly. Can this be fixed? |
Current behavior
Currently, when you intercept a request with a body of type
multipart/form-data
which includes a binary file, as well as a considerable amount of text, it is possible that the body will not be detected as typebinary
. Therefore thetoString()
method is called on the body which breaks the binary file for server-side processing.See
request.ts
I think this issue was first introduced with cypress 7.0.0, at least the issue occured for us after upgrading from 6.7.1 to 7.0.0. It does not matter if you do anything with the interceptor or not. In our case we just wanted to wait for the response before continuing the test.
Desired behavior
Form-Data bodies should be treated as binary.
Test code to reproduce
Send a form-data request with two fields, one small binary file (e.g. an empty PDF) and one field containing around 1000 words from Lorem Ipsum.
Run the test with DEBUG=cypress:net-stubbing* and you wont see the debug line
eq.body contained non-utf8 characters, treating as binary content
Reduce the text fields content to like 100 words and you will see the debug message.
Cypress Version
7.0.0+
Other
No response
The text was updated successfully, but these errors were encountered: