From 7d4cb14530273e22f3862bcc4016d327780db666 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 May 2020 15:30:17 -0400 Subject: [PATCH] Add that check to the not-equals helper and update the json value implementation to mark all non-scalars as not-equals. --- src/bin.rs | 10 +++++++++- src/renderer/renderer.rs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bin.rs b/src/bin.rs index 2971ffa..1f698a9 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -145,7 +145,15 @@ impl CompareContextElement for serde_json::Value { // Handle other serde_json::Value match other.to_any().downcast_ref::() { None => (), - Some(other_json_value) => return self == other_json_value, + Some(other_json_value) => match (self, other_json_value) { + // Non-scalar values not caught in the renderer by the + // identical-path shortcut are always not equal. + (serde_json::Value::Array(_), _) + | (_, serde_json::Value::Array(_)) + | (serde_json::Value::Object(_), _) + | (_, serde_json::Value::Object(_)) => return false, + _ => return self == other_json_value, + }, } // Handle string literals match other.to_any().downcast_ref::() { diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 712ad63..aeee5cb 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -285,6 +285,20 @@ impl<'a> DustRenderer<'a> { .iter() .map(|pair: &KVPair<'a>| (pair.key, &pair.value)) .collect(); + // Special case: when comparing two RVPaths, if the + // path is equal then dust assumes the values are + // equal (otherwise, non-scalar values are + // automatically not equal) + if Self::are_paths_identical(¶m_map) { + return match ¶meterized_block.else_contents { + None => Ok("".to_owned()), + Some(body) => { + let rendered_content = self.render_body(body, breadcrumbs, blocks)?; + Ok(rendered_content) + } + }; + } + let left_side: Result<&dyn ContextElement, WalkError> = match param_map.get("key") { None => return Ok("".to_owned()), Some(rval) => match rval {