Before this commit:
- insert password whose name is the empty string: `pass insert ""`
- now `pass`, `pass list`, and `pass show` behave like `pass show ""`.
This behavior is undesirable and it breaks other tools that rely on
`pass list`, such as the Firefox extension passff.

After this commit, `pass`, `pass list`, and `pass show` always list the
contents of the password store, even if a password with empty name
exists. `pass show ""` will still show the password as usual.
Moreover, the commit provides test cases that expose the bug.

Signed-off-by: Holger Dell <[email protected]>
---
 src/password-store.sh       |  2 +-
 tests/t0020-show-tests.sh   | 10 ++++++++++
 tests/t0060-rm-tests.sh     |  6 ++++++
 tests/t0100-insert-tests.sh |  4 ++++
 tests/t0200-edit-tests.sh   |  7 +++++++
 5 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..92717b5 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -380,7 +380,7 @@ cmd_show() {
        local path="$1"
        local passfile="$PREFIX/$path.gpg"
        check_sneaky_paths "$path"
-       if [[ -f $passfile ]]; then
+       if [[ $# -eq 1 && -f $passfile ]]; then
                if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
                        pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | 
$BASE64)" || exit $?
                        echo "$pass" | $BASE64 -d
diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh
index a4b782f..59afb5d 100755
--- a/tests/t0020-show-tests.sh
+++ b/tests/t0020-show-tests.sh
@@ -15,6 +15,16 @@ test_expect_success 'Test "show" command with spaces' '
        [[ $("$PASS" show "I am a cred with lots of spaces") == "BLAH!!" ]]
 '
 
+test_expect_success 'Test "show" command with empty pass-name' '
+       echo "Hello world" | "$PASS" insert -e "" &&
+       [[ $("$PASS" show "") == "Hello world" ]]
+'
+
+test_expect_success 'Test "show" command without pass-name' '
+       echo "Hello world" | "$PASS" insert -e "" &&
+       [[ $("$PASS" show) != "Hello world" ]]
+'
+
 test_expect_success 'Test "show" of nonexistant password' '
        test_must_fail "$PASS" show cred2
 '
diff --git a/tests/t0060-rm-tests.sh b/tests/t0060-rm-tests.sh
index 58f55f3..3f74621 100755
--- a/tests/t0060-rm-tests.sh
+++ b/tests/t0060-rm-tests.sh
@@ -22,4 +22,10 @@ test_expect_success 'Test "rm" of non-existent password' '
        test_must_fail "$PASS" rm does-not-exist
 '
 
+test_expect_success 'Test "rm": without vs empty pass-name' '
+       "$PASS" generate "" 20 &&
+       test_must_fail "$PASS" rm &&
+       "$PASS" rm ""
+'
+
 test_done
diff --git a/tests/t0100-insert-tests.sh b/tests/t0100-insert-tests.sh
index d8101ab..5eec7bc 100755
--- a/tests/t0100-insert-tests.sh
+++ b/tests/t0100-insert-tests.sh
@@ -10,4 +10,8 @@ test_expect_success 'Test "insert" command' '
        [[ $("$PASS" show cred1) == "Hello world" ]]
 '
 
+test_expect_success 'Test "insert" command without pass-name' '
+       echo "Hello world" | test_must_fail "$PASS" insert -e
+'
+
 test_done
diff --git a/tests/t0200-edit-tests.sh b/tests/t0200-edit-tests.sh
index d8d7b64..65afc92 100755
--- a/tests/t0200-edit-tests.sh
+++ b/tests/t0200-edit-tests.sh
@@ -14,4 +14,11 @@ test_expect_success 'Test "edit" command' '
        [[ $("$PASS" show cred1) == "$FAKE_EDITOR_PASSWORD" ]]
 '
 
+test_expect_success 'Test "edit": without vs empty pass-name' '
+       "$PASS" generate "" 20 &&
+       test_must_fail "$PASS" edit &&
+       "$PASS" edit "" &&
+       [[ $("$PASS" show "") == "$FAKE_EDITOR_PASSWORD" ]]
+'
+
 test_done
-- 
2.25.1

Reply via email to