diff --git a/opts/quotedstring.go b/opts/quotedstring.go index 09c68a5261..741f450b14 100644 --- a/opts/quotedstring.go +++ b/opts/quotedstring.go @@ -22,6 +22,9 @@ func (s *QuotedString) String() string { } func trimQuotes(value string) string { + if len(value) < 2 { + return value + } lastIndex := len(value) - 1 for _, char := range []byte{'\'', '"'} { if value[0] == char && value[lastIndex] == char { diff --git a/opts/quotedstring_test.go b/opts/quotedstring_test.go index 95b56f2b83..f56868b1c6 100644 --- a/opts/quotedstring_test.go +++ b/opts/quotedstring_test.go @@ -28,3 +28,13 @@ func TestQuotedStringSetWithNoQuotes(t *testing.T) { assert.NilError(t, qs.Set("something")) assert.Check(t, is.Equal("something", qs.String())) } + +func TestQuotedStringShort(t *testing.T) { + value := "" + qs := NewQuotedString(&value) + assert.NilError(t, qs.Set(`"`)) + assert.Check(t, is.Equal(`"`, qs.String())) + + assert.NilError(t, qs.Set(`'`)) + assert.Check(t, is.Equal(`'`, qs.String())) +}