Add that check to the not-equals helper and update the json value implementation to mark all non-scalars as not-equals.

This commit is contained in:
Tom Alexander 2020-05-16 15:30:17 -04:00
parent 41e4874d75
commit 7d4cb14530
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 23 additions and 1 deletions

View File

@ -145,7 +145,15 @@ impl CompareContextElement for serde_json::Value {
// Handle other serde_json::Value
match other.to_any().downcast_ref::<Self>() {
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::<String>() {

View File

@ -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(&param_map) {
return match &parameterized_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 {