From 8f49874ecc6fb8fa0de9d076cc5402280f6da840 Mon Sep 17 00:00:00 2001 From: Maximilian Burszley Date: Thu, 19 Jan 2023 13:21:17 -0500 Subject: [PATCH 1/3] adding failing test for repro of #417 showcasing failure to parse key containing periods in yaml --- tests/Settings.yaml | 1 + tests/file_yaml.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/tests/Settings.yaml b/tests/Settings.yaml index c7b1549c..10ec3cc1 100644 --- a/tests/Settings.yaml +++ b/tests/Settings.yaml @@ -15,3 +15,4 @@ place: # For override tests FOO: FOO should be overridden bar: I am bar +192.168.1.1: a string value diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index b961c2a6..1bf09659 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -26,6 +26,8 @@ struct Settings { place: Place, #[serde(rename = "arr")] elements: Vec, + #[serde(rename = "192.168.1.1")] + ip_key: String, } fn make() -> Config { @@ -35,6 +37,15 @@ fn make() -> Config { .unwrap() } +#[test] +fn test_keys_with_periods_deserialize() { + let c = make(); + + let s: Settings = c.try_deserialize().unwrap(); + + assert_eq!(s.ip_key, "a string value"); +} + #[test] fn test_file() { let c = make(); From a406fc4f4e140aa02d5401439d51391ced3959de Mon Sep 17 00:00:00 2001 From: Maximilian Burszley Date: Thu, 19 Jan 2023 13:27:27 -0500 Subject: [PATCH 2/3] adding successful example with `serde_yaml` of previous failing test --- Cargo.toml | 1 + tests/file_yaml.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9d86fd31..6e31cd7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,7 @@ pathdiff = "0.2" [dev-dependencies] serde_derive = "1.0.8" +serde_yaml = "0.9" float-cmp = "0.9" chrono = { version = "0.4", features = ["serde"] } tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "time"]} diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index 1bf09659..bf76f498 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -37,6 +37,15 @@ fn make() -> Config { .unwrap() } +#[test] +fn test_keys_with_periods_deserialize_serde_yaml() { + let map = "192.168.1.1: a string value"; + + let c: HashMap = serde_yaml::from_str(map).unwrap(); + + assert_eq!(c.get("192.168.1.1").unwrap(), "a string value"); +} + #[test] fn test_keys_with_periods_deserialize() { let c = make(); From cdb945f8a2b2fd7223d518eec874e28e38e491fa Mon Sep 17 00:00:00 2001 From: Maximilian Burszley Date: Fri, 20 Jan 2023 12:27:34 -0500 Subject: [PATCH 3/3] adding yaml-rust test case --- tests/file_yaml.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/file_yaml.rs b/tests/file_yaml.rs index bf76f498..2fea07ff 100644 --- a/tests/file_yaml.rs +++ b/tests/file_yaml.rs @@ -46,6 +46,17 @@ fn test_keys_with_periods_deserialize_serde_yaml() { assert_eq!(c.get("192.168.1.1").unwrap(), "a string value"); } +#[test] +fn test_keys_with_periods_deserialize_yaml_rust() { + use yaml_rust::YamlLoader; + + let map = "192.168.1.1: a string value"; + + let c = YamlLoader::load_from_str(map).unwrap().first().unwrap().clone(); + + assert_eq!(c["192.168.1.1"].as_str().unwrap(), "a string value"); +} + #[test] fn test_keys_with_periods_deserialize() { let c = make();