I have broken the comparison function.

master
Tom Alexander 4 years ago
parent 5b656a44ad
commit 4d28120732
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -410,18 +410,21 @@ impl CompareContextElement for serde_json::Value {
}
}
// Handle literals
match other.to_any().downcast_ref::<OwnedLiteral>() {
None => (),
Some(OwnedLiteral::LString(text)) => {
match (self, other.to_any().downcast_ref::<OwnedLiteral>()) {
(_, None) => (),
(serde_json::Value::String(self_text), Some(OwnedLiteral::LString(other_text))) => {
return self_text.partial_cmp(other_text);
}
(_, Some(OwnedLiteral::LString(text))) => {
return self.to_string().partial_cmp(text);
}
Some(OwnedLiteral::LPositiveInteger(other_num)) => {
(_, Some(OwnedLiteral::LPositiveInteger(other_num))) => {
let other_json_num: serde_json::Number = std::convert::From::from(*other_num);
return self.partial_compare(
&serde_json::Value::Number(other_json_num) as &dyn ContextElement
);
}
Some(OwnedLiteral::LFloat(other_num)) => {
(_, Some(OwnedLiteral::LFloat(other_num))) => {
let other_json_num = serde_json::Number::from_f64(*other_num);
match other_json_num {
None => return None,
@ -483,6 +486,13 @@ impl From<&OwnedLiteral> for JsonNumber {
match original {
OwnedLiteral::LPositiveInteger(num) => JsonNumber::UnsignedInteger(*num),
OwnedLiteral::LString(text) => text.into(),
OwnedLiteral::LFloat(num) => {
if num.is_nan() {
JsonNumber::Failure
} else {
JsonNumber::Decimal(*num)
}
}
}
}
}

Loading…
Cancel
Save