Open Halkcyon opened 1 year ago
Hi! Thanks for your report. Would you mind filing a patch showcasing this? I would be especially interested in a comparison of config-rs
and the plain use of the yaml crate in use by config-rs
(serde_yaml
IIRC).
Can all be in one testcase, in one file in /tests
.
If you cannot spare the time for this, just ping me and I'll do it myself.
I expected serde_yaml
, too, but it appears config-rs
is using yaml-rust
@matthiasbeyer
Ah yeah, then that crate of course.
Sorry, I maintain so many projects that I lose track sometimes and I didn't look it up. My bad.
Digging into this deeper, it also appears yaml-rust
has been unmaintained since 2020, so it's unlikely to be fixed upstream. I'll submit a patch test a bit later today.
Awesome!
So it seems that we should switch YAML implementations at some point. Maybe it is worth doing this even though there's a rewrite ongoing (although slowly, #376) where we could use serde_yaml
from the get-go.
... just thinking loud here.
Alright, repro added to tests with rust-yaml
vs. serde_yaml
@matthiasbeyer
For reference, the source of the problem has been identified: https://github.com/mehcode/config-rs/pull/418#issuecomment-1770378307
Switching YAML parser won't resolve this.
UPDATE: You can use keys with dots/periods if they're not defined at top-level. Although as referenced below, it's considered a bug (even though it'd seem necessary for the serde rename feature to work correctly to avoid config-rs
internally splitting the key into nested tables).
This issue is also a duplicate where the cause was explained:
#[derive(Debug, Deserialize)]
struct Test {
toplevel: Nested,
}
#[derive(Debug, Deserialize)]
struct Nested {
#[serde(rename = "192.168.1.1")]
ip_key: String,
#[serde(rename = "hello.world")]
hello_world: String,
nested: String,
}
Input:
toplevel:
hello.world: example
192.168.1.1: a string value
toplevel.nested: valid
Outputs:
Test {
toplevel: Nested {
ip_key: "a string value",
hello_world: "example",
nested: "valid",
},
}
When using
yaml
as a config format, the deserialization incorrectly stops at periods in keys. I do not observe this behavior when manually deserializing the string withserde_yaml
or other deserializers (such asruamel.yaml
orpyyaml
in Python). As a result, I am getting errors about keys not being present in the mapped value even though they definitely exist.MCVE:
Result: