changeset ce2afe10bb0b in sao:5.2 details: https://hg.tryton.org/sao?cmd=changeset;node=ce2afe10bb0b description: Prepare pyson result when encoding PYSON statement
The object returned by the pyson method must also be prepared before being jsonified. issue9234 review327191003 (grafted from e27a5c86fe711b7624906d132364fe8108f6f4cd) diffstat: src/pyson.js | 10 ++++++++-- tests/sao.js | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diffs (56 lines): diff -r 2a183b5b1473 -r ce2afe10bb0b src/pyson.js --- a/src/pyson.js Tue May 26 10:13:48 2020 +0200 +++ b/src/pyson.js Tue May 19 18:47:53 2020 +0200 @@ -70,6 +70,12 @@ value.seconds(), value.milliseconds() * 1000).pyson(); } + } else if ((value instanceof Object) && + !(value instanceof Sao.PYSON.PYSON)) { + value = jQuery.extend({}, value); + for (var p in value) { + this.prepare(value[p], p, value); + } } } if (parent) { @@ -82,12 +88,12 @@ pyson = this.prepare(pyson); return JSON.stringify(pyson, function(k, v) { if (v instanceof Sao.PYSON.PYSON) { - return v.pyson(); + return this.prepare(v.pyson()); } else if (v === null || v === undefined) { return null; } return v; - }); + }.bind(this)); } }); diff -r 2a183b5b1473 -r ce2afe10bb0b tests/sao.js --- a/tests/sao.js Tue May 26 10:13:48 2020 +0200 +++ b/tests/sao.js Tue May 19 18:47:53 2020 +0200 @@ -52,6 +52,12 @@ 2002, 1, 1, 12, 30, 0, 0).pyson(); var array = ["create_date", '>=', date]; var pyson_array = ["create_date", '>=', pyson_date]; + var statement = new Sao.PYSON.Equal(date, date); + var pyson_statement = { + '__class__': 'Equal', + 's1': pyson_date, + 's2': pyson_date, + }; QUnit.strictEqual(encoder.encode(), 'null', "encode()"); QUnit.strictEqual(encoder.encode(none), 'null', "encode(none)"); QUnit.strictEqual(encoder.encode(null), 'null', "encode()"); @@ -61,6 +67,8 @@ JSON.stringify(pyson_datetime), "encode(datetime)"); QUnit.strictEqual(encoder.encode(array), JSON.stringify(pyson_array), "encode(array)"); + QUnit.strictEqual(encoder.encode(statement), + JSON.stringify(pyson_statement), "encode(statement)"); }); QUnit.test('PYSON.Eval', function() {