From e87aa696ebe727eb0be01e41c67bde184ec29437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 11 Jan 2022 23:03:06 +0100 Subject: [PATCH] Use first the dotted name variable in the PYSON context issue11109 review383991002 --- src/pyson.js | 2 +- tests/sao.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pyson.js b/src/pyson.js index 43aad4f2bd..d5308789a4 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -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 --git a/tests/sao.js b/tests/sao.js index 3ad7e35b09..e80e05d310 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -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')");