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

git-secret-changes use of echo adds a newline #291

Closed
BrandonCsSanders opened this issue Dec 28, 2018 · 4 comments
Closed

git-secret-changes use of echo adds a newline #291

BrandonCsSanders opened this issue Dec 28, 2018 · 4 comments
Assignees
Labels

Comments

@BrandonCsSanders
Copy link

What are the steps to reproduce this issue?

  1. don't change FILE.pem.secret
  2. run git-secret changes FILE.pem.secret

What happens?

git-secret changes shows that a newline at the end of the file was removed

--- /dev/fd/63	2018-12-28 08:43:13.000000000 -0800
+++ FILE.pem	2018-12-27 17:37:37.000000000 -0800
@@ -20,4 +20,4 @@
ASDFASDFASDFADFSADFSAFSDASDF...elided...
+-----END RSA PRIVATE KEY-----
\ No newline at end of file

What were you expecting to happen?

no changes

Any logs, error output, etc?

    diff_result=$(diff -u <(echo "$decrypted") "$path") || true

Should instead be

    diff_result=$(diff -u <(echo -n "$decrypted") "$path") || true

What versions of software are you using?

0.2.4

@sobolevn
Copy link
Owner

@BrandonCsSanders thanks for the bug report! Can you please send a PR with the fix?

@joshrabinowitz
Copy link
Collaborator

joshrabinowitz commented Dec 30, 2018

I see what's going on here.

The underlying issue is that the $() construct used in decrypted=$(_decrypt "$path" "0" "0" "$homedir" "$passphrase") (and other places) removes trailing newlines.

So the 'right' thing to do is to get compare the output from _decrypt without stripping trailing newlines. (And use echo -n as you show).

@joshrabinowitz
Copy link
Collaborator

@BrandonCsSanders I've worked up a solution with tests for this issue at #293

@joshrabinowitz joshrabinowitz self-assigned this Jan 1, 2019
joshrabinowitz added a commit that referenced this issue Jan 1, 2019
* tests and comments about 'changes' for #291
* add 'changes' tests, improve diagnostic 
* preserve trailing newlines in diff output
* use bash trickery to preserve trailing newlines in captured text
* test 'changes' on files without newlines and when called on a non-existant file
* improve comments and variable names
@joshrabinowitz
Copy link
Collaborator

Fixed in #293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants