From f3aa2a82ea1272755fe31b3d8800a48f9e0fa366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 15 Apr 2016 14:09:35 +0700 Subject: [PATCH] Fix PYSON.Equal with Array In javascript, Array comparison doesn't work with '=='. It should use the Sao.common.compare. issue5474 review18001002 --- src/pyson.js | 6 +++++- tests/sao.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pyson.js b/src/pyson.js index 889a07985b..a49e0e9ff0 100644 --- a/src/pyson.js +++ b/src/pyson.js @@ -249,7 +249,11 @@ }); Sao.PYSON.Equal.eval_ = function(value, context) { - return value.s1 == value.s2; + if (value.s1 instanceof Array && value.s2 instanceof Array) { + return Sao.common.compare(value.s1, value.s2); + } else { + return value.s1 == value.s2; + } }; Sao.PYSON.Greater = Sao.class_(Sao.PYSON.PYSON, { diff --git a/tests/sao.js b/tests/sao.js index b846389935..11fa6d16f2 100644 --- a/tests/sao.js +++ b/tests/sao.js @@ -312,7 +312,17 @@ eval_ = new Sao.PYSON.Encoder().encode( new Sao.PYSON.Equal('foo', 'bar')); QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, - "decode(Equal('test', 'test'))"); + "decode(Equal('foo', 'bar'))"); + + eval_ = new Sao.PYSON.Encoder().encode( + new Sao.PYSON.Equal(['test'], ['test'])); + QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), true, + "decode(Equal(['test'], ['test']))"); + + eval_ = new Sao.PYSON.Encoder().encode( + new Sao.PYSON.Equal(['foo'], ['bar'])); + QUnit.strictEqual(new Sao.PYSON.Decoder().decode(eval_), false, + "decode(Equal(['foo'], ['bar']))"); }); QUnit.test('PYSON Greater', function() {