README does not say that secret add drops one trailing newline from the value while secret import keeps it #158

Open
opened 2026-10-13 00:39:03 +02:00 by clawbot · 0 comments
Collaborator

Severity: minor
A value that ends in a newline comes back one byte shorter from secret get, which the README does not mention; the workaround is secret import.

What happens: AddSecret removes exactly one trailing \n from stdin before storing, so printf 'a\n\n' | secret add x stores a\n and cat key.pem | secret add k stores the file without its final newline. secret import --source key.pem stores the bytes unchanged. README says for add only "Reads the secret value from stdin" and for get "outputs a secret value to stdout".

printf 'a\n\n' | secret add x;  secret get x | wc -c    # 2
secret import y --source <(printf 'a\n\n'); secret get y | wc -c   # 3

Where:

// Check for trailing newline in the last buffer
(AddSecret), README "Secret Management", secret add and secret get.

Correct behaviour: the behaviour itself is intended (it makes echo value | secret add store value), so the README's secret add entry says that one trailing newline is dropped, that secret import stores the file exactly, and secret get says it writes the value with no trailing newline. Whether add should offer a way to keep the newline is a product decision; not recommended.

Definition of done

  • README documents the trailing-newline rule for add and the exact-bytes rule for import and get.
  • A test stores a value ending in two newlines through add and through import and checks the stored lengths (2 and 3), so the documented rule is pinned.

Model: fable-5-1

Severity: minor A value that ends in a newline comes back one byte shorter from `secret get`, which the README does not mention; the workaround is `secret import`. What happens: `AddSecret` removes exactly one trailing `\n` from stdin before storing, so `printf 'a\n\n' | secret add x` stores `a\n` and `cat key.pem | secret add k` stores the file without its final newline. `secret import --source key.pem` stores the bytes unchanged. README says for `add` only "Reads the secret value from stdin" and for `get` "outputs a secret value to stdout". ``` printf 'a\n\n' | secret add x; secret get x | wc -c # 2 secret import y --source <(printf 'a\n\n'); secret get y | wc -c # 3 ``` Where: https://git.eeqj.de/sneak/secret/src/commit/ef0ae90768c8b18a829033b3ebd4cf98fcaeb3d1/internal/cli/secrets.go#L386 (`AddSecret`), README "Secret Management", `secret add` and `secret get`. Correct behaviour: the behaviour itself is intended (it makes `echo value | secret add` store `value`), so the README's `secret add` entry says that one trailing newline is dropped, that `secret import` stores the file exactly, and `secret get` says it writes the value with no trailing newline. Whether `add` should offer a way to keep the newline is a product decision; not recommended. **Definition of done** - README documents the trailing-newline rule for `add` and the exact-bytes rule for `import` and `get`. - A test stores a value ending in two newlines through `add` and through `import` and checks the stored lengths (2 and 3), so the documented rule is pinned. Model: fable-5-1
sneak was assigned by clawbot 2026-10-13 00:39:03 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/secret#158