mirror of https://github.com/docker/cli.git
Trim quotes from TLS flags.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
8eeed60a68
commit
52e9a69df9
|
@ -2,11 +2,13 @@ package opts
|
|||
|
||||
// QuotedString is a string that may have extra quotes around the value. The
|
||||
// quotes are stripped from the value.
|
||||
type QuotedString string
|
||||
type QuotedString struct {
|
||||
value *string
|
||||
}
|
||||
|
||||
// Set sets a new value
|
||||
func (s *QuotedString) Set(val string) error {
|
||||
*s = QuotedString(trimQuotes(val))
|
||||
*s.value = trimQuotes(val)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -16,7 +18,7 @@ func (s *QuotedString) Type() string {
|
|||
}
|
||||
|
||||
func (s *QuotedString) String() string {
|
||||
return string(*s)
|
||||
return string(*s.value)
|
||||
}
|
||||
|
||||
func trimQuotes(value string) string {
|
||||
|
@ -28,3 +30,8 @@ func trimQuotes(value string) string {
|
|||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// NewQuotedString returns a new quoted string option
|
||||
func NewQuotedString(value *string) *QuotedString {
|
||||
return &QuotedString{value: value}
|
||||
}
|
||||
|
|
|
@ -6,19 +6,23 @@ import (
|
|||
)
|
||||
|
||||
func TestQuotedStringSetWithQuotes(t *testing.T) {
|
||||
qs := QuotedString("")
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set("\"something\""))
|
||||
assert.Equal(t, qs.String(), "something")
|
||||
assert.Equal(t, value, "something")
|
||||
}
|
||||
|
||||
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
||||
qs := QuotedString("")
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set("\"something'"))
|
||||
assert.Equal(t, qs.String(), "\"something'")
|
||||
}
|
||||
|
||||
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
||||
qs := QuotedString("")
|
||||
value := ""
|
||||
qs := NewQuotedString(&value)
|
||||
assert.NilError(t, qs.Set("something"))
|
||||
assert.Equal(t, qs.String(), "something")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue