From 95bf71ef3dcab5f82b498db7eb778a8ffea6ed8b Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Mon, 22 Aug 2022 09:17:40 -0700 Subject: [PATCH] fix: Metadata now errors on empty mapping serde_yaml 0.9.7 resulted in a regression, accepting `metadata:` (empty metadata mappings) instead of returning Err. See dtolnay/serde-yaml#304 and dtolnay/serde-yaml#312 This change uses a custom deserializer to error in this case. --- src/specification.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/specification.rs b/src/specification.rs index 086280e10..b8b3c1b42 100644 --- a/src/specification.rs +++ b/src/specification.rs @@ -2336,10 +2336,27 @@ impl DemeDefaults { /// ``` #[derive(Clone, Default, Debug, Serialize, Deserialize, Eq, PartialEq)] pub struct Metadata { - #[serde(flatten)] + #[serde(flatten, deserialize_with = "require_non_empty_metadata")] metadata: std::collections::BTreeMap, } +fn require_non_empty_metadata<'de, D>( + deserializer: D, +) -> Result, D::Error> +where + D: serde::Deserializer<'de>, +{ + let buf = std::collections::BTreeMap::::deserialize(deserializer)?; + + if !buf.is_empty() { + Ok(buf) + } else { + Err(serde::de::Error::custom( + "metadata: cannot be an empty mapping".to_string(), + )) + } +} + impl Metadata { /// `true` if metadata is present, `false` otherwise fn is_empty(&self) -> bool {