Incorrectly deserializes upper case unquoted `INF` string value from a YAML file
pamburus opened this issue · comments
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 aString
as"INF"
- The test passes
Actual results
- The
INF
value is deserialized to aString
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 aString
.