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

Incorrectly deserializes upper case unquoted INF string value from a YAML file #568

Open
pamburus opened this issue Jun 4, 2024 · 0 comments
Labels

Comments

@pamburus
Copy link

pamburus commented Jun 4, 2024

Description

Here is the minimal test set to reproduce the issue

Source Files

assets/config.yaml

val: INF

src/lib.rs

#[cfg(test)]
mod tests {
    use config::Config;
    use serde::Deserialize;

    #[test]
    fn test_yaml_inf() {
        #[derive(Deserialize)]
        struct Settings {
            pub val: String,
        }

        let cfg = Config::builder()
            .add_source(config::File::with_name("assets/config.yaml"))
            .build()
            .unwrap();
        let settings = cfg.try_deserialize::<Settings>().unwrap();

        assert_eq!(settings.val, "INF");
    }
}

Cargo.toml

[package]
name = "hl-issue-288"
version = "0.1.0"
edition = "2021"

[dependencies]
config = { version = "0", features = ["yaml"] }
serde = { version = "1", features = ["derive"] }

Expected results

  • The INF value is deserialized to a String as "INF"
  • The test passes

Actual results

  • The INF value is deserialized to a String as "inf"
  • The test fails

Notes

  • The problem is that INF is deserialized to some internal representation as a float +Inf value before it is deserialized to a String.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants