X Tutup
The Wayback Machine - https://web.archive.org/web/20221207110850/https://github.com/cli/cli/issues/2998
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

Gist creation mangles binary files #2998

Closed
zambonin opened this issue Feb 18, 2021 · 8 comments · Fixed by #3042
Closed

Gist creation mangles binary files #2998

zambonin opened this issue Feb 18, 2021 · 8 comments · Fixed by #3042
Assignees
Labels
bug Something isn't working good first issue help wanted Contributions welcome p3 Affects a small number of users or is largely cosmetic

Comments

@zambonin
Copy link

zambonin commented Feb 18, 2021

Describe the bug

Creating a Gist using the gh command-line interface does not preserve the
contents of binary files.

~ $ gh --version
gh version 1.5.0 (2021-01-21)
https://github.com/cli/cli/releases/tag/v1.5.0

Steps to reproduce the behavior

Create a Gist with a binary file using gh gist create /path/to/binary-file.
I have successfully reproduced this behaviour with JPG and PDF files.
Flags that you can pass to gh gist create do not matter, nor using
gh gist create -f test.foo < /path/to/binary-file.

Expected vs actual behavior

The Gist is created successfully, but upon inspection, the binary file is not
correctly previewed and the raw contents are different.

Logs

~ $ gh gist create 10156699.jpg
- Creating gist 10156699.jpg
✓ Created gist 10156699.jpg
https://gist.github.com/07736471dd05f8406af607c4e12b269b

I have added the expected file (my GitHub profile picture) to the created
Gist
for easier inspection.

I'd wager that this is the offending line.

@zambonin zambonin added the bug Something isn't working label Feb 18, 2021
@vilmibm vilmibm added the p2 Affects more than a few users but doesn't prevent core functions label Feb 18, 2021
@mislav
Copy link
Member

mislav commented Feb 19, 2021

Since the gists API payload only accepts JSON, and I don't think it accepts base64-encoded files, I think that it's impossible to use the API to add or modify binary files. We should halt with a descriptive error when someone tries to upload a binary file, and when viewing a gist we should avoid printing binary content to stdout.

@mislav mislav added good first issue help wanted Contributions welcome p3 Affects a small number of users or is largely cosmetic and removed p2 Affects more than a few users but doesn't prevent core functions labels Feb 19, 2021
@zambonin
Copy link
Author

zambonin commented Feb 19, 2021

It would be a nice addition for the API to accept base64-encoded files, but I believe that's outside the scope of this issue.

In addition, gh gist edit could print a warning about editing binary files or refuse to do it at all.

@g14a
Copy link
Contributor

g14a commented Feb 24, 2021

@mislav I'd like to pick this up since it looks like no one is assigned. Could you assign this to me?

@mislav
Copy link
Member

mislav commented Feb 24, 2021

@g14a Go right ahead! Thank you 🙇

@g14a
Copy link
Contributor

g14a commented Feb 25, 2021

@mislav If a gist has multiple files and one of the files is a binary, and the user just tries to gh gist view <id>, do we just block the binary and render the rest of the files or halt the operation altogether? Need some input from you.

@mislav
Copy link
Member

mislav commented Feb 25, 2021

@g14a Let's render all non-binary files, and for binary files let's render the file header and a notice like “(Skipping rendering binary content)”

If the user chose to view a specific file, and that file happens to be binary, the command should be aborted with an error such as “Error: file contents is binary”.

@g14a
Copy link
Contributor

g14a commented Feb 25, 2021

got it thanks

@g14a
Copy link
Contributor

g14a commented Feb 26, 2021

Morning! @mislav Here's the PR. #3042 Would like some feedback. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue help wanted Contributions welcome p3 Affects a small number of users or is largely cosmetic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
X Tutup