Skip to content
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

Incompatibility between toml and toml_edit::easy #421

Closed
obsgolem opened this issue Jan 5, 2023 · 1 comment
Closed

Incompatibility between toml and toml_edit::easy #421

obsgolem opened this issue Jan 5, 2023 · 1 comment
Labels
A-serde Area: Serde integration C-bug Category: Things not working as expected

Comments

@obsgolem
Copy link

obsgolem commented Jan 5, 2023

The following test crashes:

use globset::Glob;
use serde::Deserialize;

#[derive(Deserialize)]
struct Test {
    foo: Vec<Glob>,
}

fn main() {
    // let test = "\"test\"";
    // let tmp = toml::de::from_str::<&str>(test).unwrap();
    // let tmp2 = toml_edit::easy::from_str::<&str>(test).unwrap();

    let text = r#"foo=["hello", "world"]"#;
    let tmp = toml::de::from_str::<Test>(text).unwrap();
    let tmp2 = toml_edit::easy::from_str::<Test>(text).unwrap();
}

With the following Cargo.toml file

[package]
edition = "2021"
name = "toml_repro"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
globset = {version = "0.4.10", features = ["serde1"]}
serde = "1.0.152"
toml = "0.5"
toml_edit = {version = "0.17.1", features = ["easy", "serde"]}

The crash occurs on line 16, showing that while toml can successfully deserialize into the Glob, toml_edit::easy cannot. This appears to be due to the implementation of Deserialize for Glob using &str::deserialize as opposed to String::deserialize.

Another incompatibility I found while trying to reproduce the issue: if you uncomment the commented lines in the code above, you will get a compiler error on line 12 but not on line 11.

@epage epage added C-bug Category: Things not working as expected A-serde Area: Serde integration labels Jan 5, 2023
@epage
Copy link
Member

epage commented Jan 18, 2023

Looking at this, I think this is more of a bug against globset as even toml can't always deserialize a &str, it would sometimes deserialize as String.

In fact, there is a globset bug for this, see BurntSushi/ripgrep#2386

As for the other issue mentioned (parsing "\"test\""), that is because toml was very loose in its parsing, with Deserializer automatically parsing any toml value when the type wasn't used for parsing a toml document. We've made this more strict in #457 where Deserializer only handles documents and ValueDeserializer handles values.

Closing this as Not Planned as the current behavior is expected

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-serde Area: Serde integration C-bug Category: Things not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants