pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.7k stars 209 forks source link

beta8: Unmarshal change from beta6/7 #757

Closed bep closed 2 years ago

bep commented 2 years ago

This may be deliberate, but I have some failing tests:

This:

[deployment]
[[deployment.targets]]

In toml.Unmarshal I now get and empty map:

map[string]interface {}{
  "targets": []interface {}{
    map[string]interface {}{},
  },
}

Vs before, a nil map:

map[string]interface {}{
  "targets": []interface {}{
    map[string]interface {}(nil),
  },
}

I'm not sure I have an opinion about what's correct ...

pelletier commented 2 years ago

Changed in this commit: https://github.com/pelletier/go-toml/pull/755/commits/420c2eb4a2d574a99e43b959ed2bbbece8706354. I did it for consistency between inline tables, array tables, and encoding/json.

[[deployment.targets]] says that there is a table in an array inside targets. An other way to write it in TOML is

deployment.targets = [{}]

So those two forms should unmarshal to the same thing. They used not to: array tables created nil maps, inline tables created empty maps. So I had to pick one. The TOML spec says that in JSON this would be equivalent to

{"deployment": {"targets": [{}]}}

Because encoding/json unmarshals the inner-most object as an empty (non-nil) map, I decided to follow the same pattern – assuming the extra allocation is worth reducing surprises for the programmer.

Does that seem reasonable to you? Is it breaking something in Hugo?

bep commented 2 years ago

Does that seem reasonable to you? Is it breaking something in Hugo?

I have some config validation checks that no fails, but I will adjust those. Sorry for the noise.