Skip to content

Commit

Permalink
[ENHANCEMENT] Allow for whitespace-trailing passwords (gopasspw#2873)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Hardt <leom.hardt@gmail.com>
  • Loading branch information
lhardt committed Oct 1, 2024
1 parent 486c165 commit 49eafdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/gopass/secrets/akv.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,13 @@ func ParseAKV(in []byte) *AKV {
continue
}

line = strings.TrimSpace(line)

key, val, found := strings.Cut(line, kvSep)
if !found {
continue
}

key = strings.TrimSpace(key)
val = strings.TrimSpace(val)
// val = strings.TrimSpace(val)
// we only store lower case keys for KV
a.kvp[key] = append(a.kvp[key], val)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/gopass/secrets/akv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ func TestSetKeyValuePairToEmptyAKV(t *testing.T) {
assert.Equal(t, "bar", v)
}

func TestAKVTrailingWhitespace(t *testing.T) {
t.Parallel()
// Expected behaviour is KEY: VALUE, with one space.
// Fallback should exist for KEY:VALUE, with no spaces.
mlValue := `foobar
defaultBehaviour: cd
sorroundedBySpace: cd
withoutSpace:cd`
s := ParseAKV([]byte(mlValue))
assert.NotNil(t, s)
v1, _ := s.Get("defaultBehaviour")
assert.Equal(t, "cd", v1)
v2, _ := s.Get("sorroundedBySpace")
assert.Equal(t, " cd \t ", v2)
v3, _ := s.Get("defaultBehaviour")
assert.Equal(t, "cd", v3)
}

func TestParseAKV(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 49eafdd

Please sign in to comment.