From 9d78a10cb8afe28c9513e396bcbfea1be9d21097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 6 Mar 2022 18:02:00 +0100 Subject: [PATCH] Manage None as value of PYSON In issue11280 review393771002 (grafted from 579d0ce4a3056c2ec60e4c208c2a8cd7e7824210) --HG-- branch : 6.0 --- src/pyson.js | 10 +++++++--- tests/sao.js | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/pyson.js b/src/pyson.js index d5308789a4..a63166f5a7 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -682,10 +682,14 @@ }); Sao.PYSON.In.eval_ = function(value, context) { - if (value.v.indexOf) { - return Boolean(~value.v.indexOf(value.k)); + if (value.v) { + if (value.v.indexOf) { + return Boolean(~value.v.indexOf(value.k)); + } else { + return !!value.v[value.k]; + } } else { - return !!value.v[value.k]; + return false; } }; Sao.PYSON.In.init_from_object = function(obj) { diff --git a/tests/sao.js b/tests/sao.js index a95813ed43..f3c39a8457 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -772,6 +772,12 @@ new Sao.PYSON.In('test', [])); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, "decode(In('test', []))"); + + eval_ = new Sao.PYSON.Encoder().encode( + new Sao.PYSON.In('test', new Sao.PYSON.Eval('foo', []))); + QUnit.strictEqual(new Sao.PYSON.Decoder({'foo': null}).decode(eval_), + false, "decode(In('test', Eval('foo', [])))"); + QUnit.strictEqual(new Sao.PYSON.In('foo', ['foo', 'bar']).toString(), 'In("foo", ["foo", "bar"])'); });