Escape dots in key
How to access nested fields when some key contains dots? ['valid.key.with.dot'] doesn't work.
config is currently designed such that fields must be identifiers. The . is used to traverse nested configuration. I didn't think it was even possible for you to set a variable with dots in the name. Can you share a small example?
If the key with dots appears at a nested level, it won't be interpreted as a sequence of identifiers but as a single key of table. For example,
let source = config::File::from_str(
r#"{
"foo.bar": 42,
"nested": {
"foo.bar": 42
}
}"#,
config::FileFormat::Json);
produces
cache: Value {
origin: None,
kind: Table(
{
"foo": Value {
origin: None,
kind: Table(
{
"bar": Value {
origin: None,
kind: Integer(
42
)
}
}
)
},
"nested": Value {
origin: None,
kind: Table(
{
"foo.bar": Value {
origin: None,
kind: Integer(
42
)
}
}
)
}
}
)
}
but I'd like to visit [nested]['foo.bar']. (I guess I might have misunderstood config's design.)
Ah. That's a bug then. It should have produced a table at nested.foo with a key bar that is a simple Value which would have then worked fine with config.get("nested.foo.bar").
It would be best if config could support identifiers with dots as well as a complete set of JSONPath queries. Sometimes it's convenient to use domains as key.
I'm getting hit by this on linux where something is sometimes setting the following environment variables:
PULSE_PROP_OVERRIDE_application.icon_name=konsole
PULSE_PROP_OVERRIDE_application.name=Konsole
PULSE_PROP_OVERRIDE_application.version=17.12.3
I have no idea where these are being set, and I can't unset them because they're not valid identifiers.
As you already mentioned it's not normally possible to set them, at least not through the shell (I think you can probably set them from C). According to the posix standard, applications are required not to break in the prescence of invalid variable names, but are not required to handle them, so is it possible config could just ignore them and carry on? It currently barfs and returns an empty environment when these are set.
This is not as easy to solve, patches are welcome though!