-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check --config for dotted keys only #10176
Conversation
r? @Eh2406 (rust-highfive has picked a reviewer for you, use r? to override) |
This addresses the remaining unresolved issue for `config-cli` (rust-lang#7722).
f22e525
to
80fbfed
Compare
Personally I don't think that this is a great solution for the problem which is to write an inline toml parser for the keys here. I think it would be better to expose more APIs from the |
@alexcrichton I personally disagree here — it seems odd to me for |
I also would prefer to not have a partial TOML parser here. Unfortunately at the moment the TOML story is in flux. My original intent was to expose a raw interface in the |
Would love to hear your thoughts @epage! A secondary observation here is that we could always swap out the custom validation logic here for something provided by |
I remember wanting to remove this before and had problems. It looks like those have since been addressed (I think with changes to repr). Before, we were taking any string and trying to infer what its repr would be. Now we only parse actualy dotted keys. This will hopefully help with rust-lang/cargo#10176
Let me see if I understand the problem being solved. We are adding a
In doing so, we are trying to parse In using toml, we want to restrict the syntax so someone can't inject more complex toml expressions (tables, etc). Is that the gist? We have a |
I remember wanting to remove this before and had problems. It looks like those have since been addressed (I think with changes to repr). Before, we were taking any string and trying to infer what its repr would be. Now we only parse actualy dotted keys. This will hopefully help with rust-lang/cargo#10176 BREAKING CHANGE: `Key::from_str` will accept fewer values and will return slightly different errors.
I think we specifically want to support any single TOML dotted-key expression in From the docs, it looks like |
I remember wanting to remove this before and had problems. It looks like those have since been addressed (I think with changes to repr). Before, we were taking any string and trying to infer what its repr would be. Now we only parse actualy dotted keys. This will hopefully help with rust-lang/cargo#10176 BREAKING CHANGE: `Key::from_str` will accept fewer values and will return slightly different errors.
Oh, and for the value I think we want to support any value that's not an inline table. Arrays, for example, are fine. |
We support parsing a lot of expressions to help users to edit their toml document from real world code. One thing that was missing was dotted key parsing. Also, this will hopefully help with rust-lang/cargo#10176
You are right, I forgot that it was only a simple key and not a full key path. I think its reasonable for us to extend this so people can parse keys, see toml-rs/toml#274.
This is making me wonder, why not parse the |
I don't immediately see a way to inspect a I'm working on an update to this PR now that moves to |
We support parsing a lot of expressions to help users to edit their toml document from real world code. One thing that was missing was dotted key parsing. Also, this will hopefully help with rust-lang/cargo#10176
My current draft looks something like this: // We only want to allow "dotted key" (see https://toml.io/en/v1.0.0#keys)
// expressions followed by a value that's not an "inline table"
// (https://toml.io/en/v1.0.0#inline-table). There isn't a way to constrain the
// toml_edit parser to _just_ an expression of that form, but we can get pretty far
// by checking if any `=`-separated prefix parses as the `toml_edit::Key` type. If
// there are multiple `=` in there, we need to split at each one until parsing
// succeeds, because the first `=` could be in a "-quoted string for example.
let mut separator = None;
for (ind, c) in arg.char_indices() {
if c != '=' {
continue;
}
if let Ok(_) = arg[..ind].parse::<toml_edit::Key>() {
separator = Some(ind);
break;
}
}
let separator = if let Some(s) = separator {
s
} else {
bail!(
"--config argument `{}` was not a TOML dotted key expression (a.b.c = _)",
arg
);
};
let toml_v = arg[(separator + 1)..]
.trim()
.parse::<toml_edit::Value>()
.with_context(|| {
format!("failed to parse value from --config argument `{}`", arg)
})?;
if let toml_edit::Value::InlineTable(_) = toml_v {
bail!(
"--config argument `{}` uses inline table values, which are not accepted",
arg,
);
}
// Rather than trying to piece the key/value back into a toml::Value, we just parse
// the whole argument again now that we know it has the right format.
let toml_v = toml::from_str(arg).with_context(|| {
format!("failed to parse value from --config argument `{}`", arg)
})?; Though it fails on dotted key expressions as expected. |
Release is now out with
For
Haven't messed with |
I'm fiddling with getting to use Edit: ah, I want |
Fixed up following the merge of #10086. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Would it be possible to also reject comments or other decoration?
Parts to check Alternatively,. this could be implemented via visit. Looks like we don't expose whats needed for dealing with keys. I might get a change out real quick for that. |
Working on a fix to check for non-empty decorators (whitespace should be allowed I think), but am running into the fact that |
How come you are dealing with |
I wanted to write a helper to deal with the non-recursive variants |
Would love if you have the time to look over the way I implemented this too @epage and see if it matches what you expected to see? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decor handling looks good.
Thanks! ❤️ @bors r+ |
📌 Commit 02e071c has been approved by |
☀️ Test successful - checks-actions |
Update cargo 9 commits in 95bb3c92bf516017e812e7f1c14c2dea3845b30e..1c034752de0df744fcd7788fcbca158830b8bf85 2022-01-18 17:39:35 +0000 to 2022-01-25 22:36:53 +0000 - Sync toml_edit versions (rust-lang/cargo#10329) - Check --config for dotted keys only (rust-lang/cargo#10176) - Remove deprecated --host arg for search and publish cmds (rust-lang/cargo#10327) - doc: it's valid to use OUT_DIR for intermediate artifacts (rust-lang/cargo#10326) - Use local git info for version. (rust-lang/cargo#10323) - Fix documenting with undocumented dependencies. (rust-lang/cargo#10324) - do not compile test for bins flagged as `test = false` (rust-lang/cargo#10305) - Port cargo from toml-rs to toml_edit (rust-lang/cargo#10086) - Fix new::git_default_branch with different default (rust-lang/cargo#10306)
Port over rust-lang/cargo#10176 to nextest.
Port over rust-lang/cargo#10176 to nextest.
This addresses the remaining unresolved issue for
config-cli
(#7722).