croc icon indicating copy to clipboard operation
croc copied to clipboard

Pipe (stdout) mode adds newline

Open fungs opened this issue 2 years ago • 3 comments

Describe the bug

When writing the transfered content to a file or pipe using --stdout, the content is not equivalent to the original. Instead, the receiver command adds a trailing newline (\n, LF, hex: 0a).

To Reproduce

Steps to reproduce the behavior (Linux/Bash):

  1. dd if=/dev/urandom of=binary_data_sent bs=1MB count=1
  2. random_secret=$RANDOM && echo $random_secret
  3. croc --debug send --code $random_secret < binary_data_sent
  4. croc --yes --stdout $random_secret > binary_data_received
  5. md5sum binary_data_received binary_data_sent
  6. diff <(xxd binary_data_sent) <(xxd binary_data_received)

Expected behaviour

  1. The md5 hash should be the same
  2. the diff shoult be empty

Version

v9.6.5-8ab65d0

fungs avatar Oct 20 '23 09:10 fungs

happy to accept a PR for this, probably only need to change Println to Print

schollz avatar Feb 08 '24 20:02 schollz

Probably, maybe, I don't know. I'm not using the software, just tested it for understanding and stumbled over this obvious bug.

fungs avatar Feb 08 '24 21:02 fungs

https://github.com/schollz/croc/blob/ce91e3b420b47d26ea0c3c9d40e437b714c70e2d/src/croc/croc.go#L1087C1-L1102C3

I've identified the issue occurring at line 1101 in src/croc/croc.go. When the Stdout option is set to true, the code logic in this segment necessitates the deletion of the corresponding file and the output of a newline character at the end. It appears that this additional newline character is causing the problem. In my opinion, it would be more appropriate to direct the newline character output to os.Stderr in this context.

TravisRoad avatar Feb 15 '24 03:02 TravisRoad

IMO, this issue can be closed.

TravisRoad avatar Feb 24 '24 17:02 TravisRoad