Decoder: allow commas in tags (#693)
This commit is contained in:
+9
-2
@@ -1163,8 +1163,15 @@ func forEachField(t reflect.Type, path []int, do func(name string, path []int))
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
name, ok := f.Tag.Lookup("toml")
|
name := f.Tag.Get("toml")
|
||||||
if !ok {
|
if name == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if i := strings.IndexByte(name, ','); i >= 0 {
|
||||||
|
name = name[:i]
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
name = f.Name
|
name = f.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2698,6 +2698,34 @@ world'`,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalTags(t *testing.T) {
|
||||||
|
type doc struct {
|
||||||
|
Dash string `toml:"-,"`
|
||||||
|
Ignore string `toml:"-"`
|
||||||
|
A string `toml:"hello"`
|
||||||
|
B string `toml:"comma,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
data := `
|
||||||
|
'-' = "dash"
|
||||||
|
Ignore = 'me'
|
||||||
|
hello = 'content'
|
||||||
|
comma = 'ok'
|
||||||
|
`
|
||||||
|
|
||||||
|
d := doc{}
|
||||||
|
expected := doc{
|
||||||
|
Dash: "dash",
|
||||||
|
Ignore: "",
|
||||||
|
A: "content",
|
||||||
|
B: "ok",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := toml.Unmarshal([]byte(data), &d)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, expected, d)
|
||||||
|
}
|
||||||
|
|
||||||
func TestASCIIControlCharacters(t *testing.T) {
|
func TestASCIIControlCharacters(t *testing.T) {
|
||||||
invalidCharacters := []byte{0x7F}
|
invalidCharacters := []byte{0x7F}
|
||||||
for c := byte(0x0); c <= 0x08; c++ {
|
for c := byte(0x0); c <= 0x08; c++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user