question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Downloading a PDF with intercept corrupts the file

See original GitHub issue

Current behavior

Downloading with intercept on a URI corrupts the file contents.

This is #9359 on the download side. The fix made for #9359 isn’t the “right” fix. Yes, it avoids corrupting multi-part file uploads, but it corrupts all binary downloads.

The problem is STILL here: https://github.com/cypress-io/cypress/blob/develop/packages/net-stubbing/lib/server/intercept-request.ts#L116

You cannot convert a buffer to a string with toString() unless you know the data is a string, and not binary data.

This also probably messes with download of files which are not utf8 encoded, for example something encoded in utf16le, since you will be converting them into utf8 before you save them.

I didn’t dig deep enough to understand why the toString() is required at all. If other layers are expecting a string, then let THEM do the conversion when they are sure they know they have a string.

For the times you are doing toString() you may want to check the ContentType header for the encoding and put that in toString() if Node will support it, but LOADS of uncommon encodings are not supported in Node, though these are unlikely to be tested with Cypress.

Desired behavior

Downloading with intercept should not corrupt the file.

Test code to reproduce

https://github.com/nickpalmer/cypress-intercept-buffer-bug

Versions

6.3.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:13
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
johnnyperkinscommented, Feb 13, 2021

This is also an issue when trying to upload a file. Uploading to s3 with header Content-MD5 fails since the request body is binary data and the toString() changes it’s hash.

0reactions
pedrovgscommented, Apr 19, 2022

Hi! I’d need to intercept a request and return a pdf file I have saved as a fixture but looks like this issue is breaking the fixture integration and corrupting the data. Do you know if there is any workaround we can use or something we can do to fix this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Re: When downloading, says file corrupt - 11702644
When downloading, says file corrupt · 1- Make sure that you have the most recent version of Acrobat Reader installed. · 2- Try...
Read more >
Repair Corrupted or Damaged PDF File with 4 Ways
Try a professional PDF repair software. Wondershare Repairit, a professional tool that can fix corrupted PDF files easily. It can extract and repair...
Read more >
How to Repair a Corrupt PDF File - iLovePDF
Recover lost data with a PDF Repair tool · Navigate to our Repair PDF tool. · Select the file you want to repair...
Read more >
Public Law 107–56—OCT. 26, 2001 - Congress.gov
to Intercept and Obstruct Terrorism (USA PATRIOT ACT) Act of 2001''. ... Inclusion of foreign corruption offenses as money laundering crimes. Sec. 316....
Read more >
How to repair damaged PDF file?
Adobe PDF repair tool for corrupted documents. eRepair PDF is an effective solution for the repair of corrupt or damaged PDF data files....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found