changeset e27a5c86fe71 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=e27a5c86fe71
description:
Prepare pyson result when encoding PYSON statement
The object returned by the pyson method must also be prepared before
being
jsonified.
issue9234
review327191003
diffstat:
src/pyson.js | 10 ++++++++--
tests/sao.js | 8 ++++++++
2 files changed, 16 insertions(+), 2 deletions(-)
diffs (56 lines):
diff -r 53ff6c9d8393 -r e27a5c86fe71 src/pyson.js
--- a/src/pyson.js Mon May 18 13:53:59 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 53ff6c9d8393 -r e27a5c86fe71 tests/sao.js
--- a/tests/sao.js Mon May 18 13:53:59 2020 +0200
+++ b/tests/sao.js Tue May 19 18:47:53 2020 +0200
@@ -54,6 +54,12 @@
pyson_datetime.start = null;
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()");
@@ -63,6 +69,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() {