Skip to content
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

Do not attempt string replacements on binary files #1405

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

iowillhoit
Copy link
Contributor

@iowillhoit iowillhoit commented Aug 22, 2024

What does this PR do?

If you attempt to do string replacements on a binary file (e.g. an image) it will become corrupt due to the .toString() conversion. This change prevents string replacements from running on binary files.

@W-16560716@

Testing

  • Create a salesforce project and create a scratch org
  • Either manually or from the Setup UI, add a staticresource image
    • If you created it in the UI, retrieve it to your local project
  • Add this config to your sfdx-project.json
"replacements": [
    {
      "glob": "force-app/main/default/**/**",
      "stringToReplace": "replaceMe",
      "replaceWithEnv": "FOO"
    }
  ]
  • Run export FOO="bar" or it will complain that the env is not set
  • Before this PR, run sf project deploy start --source-dir force-app/main/default/staticresources
  • You will notice that the image shows as changed
  • Go to the staticresource in the browser and you will notice that the size is much larger and it will also fail to render if you click View file
  • Note: Do you retrieve again or your local image will become corrupt
  • Now pull this branch, yarn link it in plugin-deploy-retrieve, and sf plugins link . PDR
  • Re-run sf project deploy start --source-dir force-app/main/default/staticresources
  • You will see that it shows as changed again, but this is because it is replacing the corrupt version
  • Check out the image in the UI, it should load.
  • Run sf project deploy start --source-dir force-app/main/default/staticresources on final time and it should show as unchanged

Notes

Here are some screenshots showing the file size differences. There values are used in the NUTs to confirm the file did not change.
OK:
Screenshot 2024-08-22 at 2 18 38 PM

Corrupt:
Screenshot 2024-08-22 at 2 20 31 PM

Proof from test:
Screenshot 2024-08-22 at 2 17 58 PM

@iowillhoit iowillhoit requested a review from a team as a code owner August 22, 2024 19:54
@WillieRuemmele
Copy link
Member

WillieRuemmele commented Aug 26, 2024

QA Notes


following the instructions, without the changes, the SR was over the 5Mb limit

Component Failures [2]
==========================================================
| Type  Name Problem                           Line:Column 
| ───── ──── ───────────────────────────────── ─────────── 
| Error heif static resource cannot exceed 5MB             
| Error jpeg static resource cannot exceed 5MB       

✅ : once I linked, it deployed
✅ : correct size
✅ : correct source tracking
✅ : rendered in browser
✅ : verified with .pdf/ .heic / .jpeg

@WillieRuemmele WillieRuemmele merged commit 5f819ec into main Aug 26, 2024
76 of 77 checks passed
@WillieRuemmele WillieRuemmele deleted the ew/replacements-on-strings branch August 26, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants