changeset 6761c7b46738 in sao:5.6
details: https://hg.tryton.org/sao?cmd=changeset;node=6761c7b46738
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 7ff28851a9d6 -r 6761c7b46738 src/pyson.js
--- a/src/pyson.js      Tue May 26 10:12:55 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 7ff28851a9d6 -r 6761c7b46738 tests/sao.js
--- a/tests/sao.js      Tue May 26 10:12:55 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() {

Reply via email to