<html><head></head><body>Just a note: instead of `! -z` use `-n`<br><br>I agree on that an empty name should be an error and not accepted.<br><br>Cheers!<br><br><div class="gmail_quote">On July 12, 2019 12:24:22 PM GMT-03:00, "Rémi Lapeyre" <remi.lapeyre@henki.fr> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">Saving a password with an empty name could happen (when doing `pass<br>insert "$passname"` for example) and would break `pass show` as it would<br>show this passworld instead of listing them all. This behavior would<br>break some third party integrations like passff.<br><br>This changes both `pass insert` to refuse saving such a password and fix<br>`pass show` to list the passwords since a ".gpg" file could still appear<br>from a backup or a bad git commit (note that the empty password won't<br>show up as its file will be ".gpg" and be hidden).<hr> src/password-store.sh       | 3 ++-<br> tests/t0020-show-tests.sh   | 7 +++++++<br> tests/t0100-insert-tests.sh | 5 +++++<br> 3 files changed, 14 insertions(+), 1 deletion(-)<br><br>diff --git a/src/password-store.sh b/src/password-store.sh<br>index b99460c..62b449e 100755<br>--- a/src/password-store.sh<br>+++ b/src/password-store.sh<br>@@ -379,7 +379,7 @@ cmd_show() {<br>  local path="$1"<br>     local passfile="$PREFIX/$path.gpg"<br>  check_sneaky_paths "$path"<br>- if [[ -f $passfile ]]; then<br>+  if [[ -f $passfile && ! -z "$path" ]]; then<br>                 if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then<br>                   pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | $BASE64)" || exit $?<br>                     echo "$pass" | $BASE64 -d<br>@@ -444,6 +444,7 @@ cmd_insert() {<br> <br>    [[ $err -ne 0 || ( $multiline -eq 1 && $noecho -eq 0 ) || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--echo,-e | --multiline,-m] [--force,-f] pass-name"<br>         local path="${1%/}"<br>+        [[ -z "$path" ]] && die "Cannot insert a password with an empty name."<br>    local passfile="$PREFIX/$path.gpg"<br>  check_sneaky_paths "$path"<br>  set_git "$passfile"<br>diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh<br>index a4b782f..3acdc39 100755<br>--- a/tests/t0020-show-tests.sh<br>+++ b/tests/t0020-show-tests.sh<br>@@ -15,6 +15,13 @@ test_expect_success 'Test "show" command with spaces' '<br>      [[ $("$PASS" show "I am a cred with lots of spaces") == "BLAH!!" ]]<br> '<br> <br>+test_expect_success 'Test "show" with empty file' '<br>+     mv "$PASSWORD_STORE_DIR"{cred1.gpg,.gpg}<br>+   "$PASS" show<br>+       [[ $("$PASS" show) == "Password Store<br>+\`-- I\\ am\\ a\\ cred\\ with\\ lots\\ of\\ spaces" ]]<br>+'<br>+<br> test_expect_success 'Test "show" of nonexistant password' '<br>     test_must_fail "$PASS" show cred2<br> '<br>diff --git a/tests/t0100-insert-tests.sh b/tests/t0100-insert-tests.sh<br>index d8101ab..3bfc482 100755<br>--- a/tests/t0100-insert-tests.sh<br>+++ b/tests/t0100-insert-tests.sh<br>@@ -10,4 +10,9 @@ test_expect_success 'Test "insert" command' '<br>       [[ $("$PASS" show cred1) == "Hello world" ]]<br> '<br> <br>+test_expect_success 'Test insert empty password' '<br>+ echo "Hello world" | "$PASS"  insert -e ""<br>+     [[ $? == 1 ]]<br>+'<br>+<br> test_done</pre></blockquote></div><br>-- <br>HacKan || Iván</body></html>