Skip to content

Commit 1ecc731

Browse files
fix: Add support for float yaml hash keys
1 parent 6ca539c commit 1ecc731

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/file/format/yaml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn from_yaml_value(
5151
yaml::Yaml::String(k) => m.insert(k.to_owned(), from_yaml_value(uri, value)?),
5252
yaml::Yaml::Integer(k) => m.insert(k.to_string(), from_yaml_value(uri, value)?),
5353
yaml::Yaml::Boolean(k) => m.insert(k.to_string(), from_yaml_value(uri, value)?),
54+
yaml::Yaml::Real(k) => m.insert(k.to_owned(), from_yaml_value(uri, value)?),
5455
other => Err(Box::new(UnsupportedHashKeyError(format!("{other:?}"))))?,
5556
};
5657
}

tests/testsuite/file_yaml.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,12 @@ inner_bool:
385385

386386
#[test]
387387
fn test_yaml_parsing_float_hash() {
388-
let result = Config::builder()
388+
#[derive(Debug, Deserialize)]
389+
struct TestStruct {
390+
inner_float: HashMap<String, String>,
391+
}
392+
393+
let config = Config::builder()
389394
.add_source(File::from_str(
390395
r#"
391396
inner_float:
@@ -394,10 +399,10 @@ inner_float:
394399
"#,
395400
FileFormat::Yaml,
396401
))
397-
.build();
398-
assert!(result.is_err());
399-
assert_data_eq!(
400-
result.unwrap_err().to_string(),
401-
str!["Cannot parse Real(\"0.1\") because it is an unsupported hash key type"]
402-
);
402+
.build()
403+
.unwrap()
404+
.try_deserialize::<TestStruct>()
405+
.unwrap();
406+
assert_eq!(config.inner_float.get("0.1").unwrap(), "float 0.1");
407+
assert_eq!(config.inner_float.get("0.2").unwrap(), "float 0.2");
403408
}

0 commit comments

Comments
 (0)