From 1092e979ad0f81e40cba151f87e692f49c52dd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 21 Nov 2016 21:00:43 +0100 Subject: [PATCH] Order the keys of Dict value to allow comparison with JSON.stringify This will ensure that the JSON.stringify will dump the keys always in the same order. Even if the key order is a implementation detail of the browser, constructing a new Object using always the same order will guarantee a stable stringification. issue6045 review33631002 --- src/model.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/model.js b/src/model.js index 6f7d802488..06d6bf6706 100644 --- a/src/model.js +++ b/src/model.js @@ -2392,6 +2392,23 @@ Sao.field.Dict = Sao.class_(Sao.field.Field, { _default: {}, + set: function(record, value) { + if (value) { + // Order keys to allow comparison with stringify + var keys = []; + for (var key in value) { + keys.push(key); + } + keys.sort(); + var new_value = {}; + for (var index in keys) { + key = keys[index]; + new_value[key] = value[key]; + } + value = new_value; + } + Sao.field.Dict._super.set.call(this, record, value); + }, get: function(record) { return (Sao.field.Dict._super.get.call(this, record) || this._default);