Skip to content

Commit

Permalink
fix kv builder out of bounds panic on single backslash (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccapurso authored Mar 16, 2022
1 parent b459752 commit 895daab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kv-builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (b *Builder) add(raw string) error {
}

value = string(contents)
} else if value[0] == '\\' && value[1] == '@' {
} else if len(value) >= 2 && value[0] == '\\' && value[1] == '@' {
value = value[1:]
} else if value == "-" {
if b.Stdin == nil {
Expand Down
17 changes: 17 additions & 0 deletions kv-builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ func TestBuilder_escapedAt(t *testing.T) {
}
}

func TestBuilder_singleBackslash(t *testing.T) {
var b Builder
err := b.Add("foo=bar", "bar=\\")
if err != nil {
t.Fatalf("err: %s", err)
}

expected := map[string]interface{}{
"foo": "bar",
"bar": "\\",
}
actual := b.Map()
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}

func TestBuilder_stdin(t *testing.T) {
var b Builder
b.Stdin = bytes.NewBufferString("baz")
Expand Down

0 comments on commit 895daab

Please sign in to comment.