changeset b0df47b1f914 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=b0df47b1f914
description:
        Use first the dotted name variable in the PYSON context

        issue11109
        review383991002
diffstat:

 src/pyson.js |   2 +-
 tests/sao.js |  14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

diffs (36 lines):

diff -r e87a0586b672 -r b0df47b1f914 src/pyson.js
--- a/src/pyson.js      Thu Jan 06 00:36:48 2022 +0100
+++ b/src/pyson.js      Tue Jan 11 23:03:06 2022 +0100
@@ -173,7 +173,7 @@
 
     Sao.PYSON.Eval.eval_ = function(value, context) {
         var idx = value.v.indexOf('.');
-        if (idx >= 0) {
+        if ((idx >= 0) && !(value.v in context)) {
             return Sao.PYSON.Eval.eval_({
                 'v': value.v.substring(idx + 1),
                 'd': value.d,
diff -r e87a0586b672 -r b0df47b1f914 tests/sao.js
--- a/tests/sao.js      Thu Jan 06 00:36:48 2022 +0100
+++ b/tests/sao.js      Tue Jan 11 23:03:06 2022 +0100
@@ -1244,6 +1244,20 @@
         });
     });
 
+    QUnit.test('PYSON.EVal dot notation in context', function() {
+        var eval_ = new Sao.PYSON.Encoder().encode(
+            new Sao.PYSON.Eval('foo.bar', 0));
+        var ctx = {
+            'foo.bar': 1,
+            'foo': {
+                'bar': 0,
+            },
+        };
+        QUnit.strictEqual(
+            new Sao.PYSON.Decoder(ctx).decode(eval_), 1,
+            "decode(" + JSON.stringify(ctx) + ")");
+    });
+
     QUnit.test('PYSON eval', function() {
         QUnit.strictEqual(eval_pyson('True'), true, "eval_pyson('True')");
         QUnit.strictEqual(eval_pyson('False'), false, "eval_pyson('False')");

Reply via email to