diff --git a/src/jsonata/jsonata.py b/src/jsonata/jsonata.py index 0a8392b..55476e0 100644 --- a/src/jsonata/jsonata.py +++ b/src/jsonata/jsonata.py @@ -800,9 +800,9 @@ def evaluate_equality_expression(self, lhs: Optional[Any], rhs: Optional[Any], o result = None if op == "=": - result = lhs == rhs # isDeepEqual(lhs, rhs); + result = utils.Utils.is_deep_equal(lhs, rhs) elif op == "!=": - result = lhs != rhs # !isDeepEqual(lhs, rhs); + result = not utils.Utils.is_deep_equal(lhs, rhs) return result # diff --git a/src/jsonata/utils.py b/src/jsonata/utils.py index 242e134..8b43aea 100644 --- a/src/jsonata/utils.py +++ b/src/jsonata/utils.py @@ -90,6 +90,27 @@ def create_sequence_from_iter(it: Iterable) -> list: sequence.sequence = True return sequence + @staticmethod + def is_deep_equal(lhs: Optional[Any], rhs: Optional[Any]) -> bool: + if isinstance(lhs, list) and isinstance(rhs, list): + if len(lhs) != len(rhs): + return False + for ii, _ in enumerate(lhs): + if not Utils.is_deep_equal(lhs[ii], rhs[ii]): + return False + return True + elif isinstance(lhs, dict) and isinstance(rhs, dict): + if lhs.keys() != rhs.keys(): + return False + for key in lhs.keys(): + if not Utils.is_deep_equal(lhs[key], rhs[key]): + return False + return True + if lhs == rhs and type(lhs) == type(rhs): + return True + + return False + class JList(list): sequence: bool outer_wrapper: bool diff --git a/tests/types_test.py b/tests/types_test.py index 26afcad..0b8b076 100644 --- a/tests/types_test.py +++ b/tests/types_test.py @@ -40,3 +40,10 @@ def test_ignore(self): expr2.set_validate_input(False) with pytest.raises(TypeError): expr2.evaluate({"a": a_set}) + + def test_fix_issue_21(self): + """ + https://github.com/rayokota/jsonata-python/issues/21 + """ + assert jsonata.Jsonata("true = 1").evaluate({}) is False + assert jsonata.Jsonata("false = 0").evaluate({}) is False