From 4645530473b86b30deaf2d5c51b6c9bc59b4f064 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 17 May 2020 15:52:38 -0400 Subject: [PATCH] Use the render function when doing string coercion for json values. --- src/bin.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin.rs b/src/bin.rs index 7e0f6ff..34f0f02 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -177,7 +177,15 @@ impl CompareContextElement for serde_json::Value { // When doing a greater than or less than comparison, // javascript coerces objects into "[object Object]". if let serde_json::Value::Object(_) = self { - return OwnedLiteral::LString("[object Object]".to_owned()).partial_compare(other); + return OwnedLiteral::LString(self.render(&Vec::new()).unwrap_or("".to_owned())) + .partial_compare(other); + } + + // When doing a greater than or less than comparison + // javascript turns arrays into strings. + if let serde_json::Value::Array(_) = self { + return OwnedLiteral::LString(self.render(&Vec::new()).unwrap_or("".to_owned())) + .partial_compare(other); } // Handle other serde_json::Value