Do not panic on empty quoted string argument
Signed-off-by: Sylvain Baubeau <lebauce@gmail.com>
This commit is contained in:
parent
ea96e160e4
commit
5d96e09628
|
@ -22,6 +22,10 @@ func (s *QuotedString) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimQuotes(value string) string {
|
func trimQuotes(value string) string {
|
||||||
|
if len(value) < 2 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
lastIndex := len(value) - 1
|
lastIndex := len(value) - 1
|
||||||
for _, char := range []byte{'\'', '"'} {
|
for _, char := range []byte{'\'', '"'} {
|
||||||
if value[0] == char && value[lastIndex] == char {
|
if value[0] == char && value[lastIndex] == char {
|
||||||
|
|
|
@ -16,15 +16,19 @@ func TestQuotedStringSetWithQuotes(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
||||||
value := ""
|
qs := NewQuotedString(new(string))
|
||||||
qs := NewQuotedString(&value)
|
|
||||||
assert.Check(t, qs.Set(`"something'`))
|
assert.Check(t, qs.Set(`"something'`))
|
||||||
assert.Check(t, is.Equal(`"something'`, qs.String()))
|
assert.Check(t, is.Equal(`"something'`, qs.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
||||||
value := ""
|
qs := NewQuotedString(new(string))
|
||||||
qs := NewQuotedString(&value)
|
|
||||||
assert.Check(t, qs.Set("something"))
|
assert.Check(t, qs.Set("something"))
|
||||||
assert.Check(t, is.Equal("something", qs.String()))
|
assert.Check(t, is.Equal("something", qs.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQuotedStringEmptyOrSingleCharString(t *testing.T) {
|
||||||
|
qs := NewQuotedString(new(string))
|
||||||
|
assert.Check(t, qs.Set(""))
|
||||||
|
assert.Check(t, qs.Set("'"))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue