Skip to content

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

Open
@pamburus

Description

@pamburus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions