Use first the dotted name variable in the PYSON context

issue11109
review383991002
This commit is contained in:
Cédric Krier
2022-01-11 23:03:06 +01:00
parent c52e78e7f1
commit e87aa696eb
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -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,
+14
View File
@@ -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')");