1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #43142 from lebauce/fix-panic-on-empty-quoted-strings

Do not panic on empty quoted string argument
This commit is contained in:
Tianon Gravi 2022-02-16 11:54:34 -08:00 committed by GitHub
commit c94596abc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -22,6 +22,10 @@ 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 {

View file

@ -16,15 +16,19 @@ func TestQuotedStringSetWithQuotes(t *testing.T) {
}
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
qs := NewQuotedString(new(string))
assert.Check(t, qs.Set(`"something'`))
assert.Check(t, is.Equal(`"something'`, qs.String()))
}
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
qs := NewQuotedString(new(string))
assert.Check(t, qs.Set("something"))
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("'"))
}