Skip to content

Commit

Permalink
Fixes #4740 - RangeError: Maximum call stack size exceeded while upda…
Browse files Browse the repository at this point in the history
…ting organizations.

Co-authored-by: Florian Liebe <fl@zammad.com>
  • Loading branch information
rolfschmidt and fliebe92 committed Aug 2, 2023
1 parent 4ddfd64 commit 81448d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/assets/javascripts/application.js
Expand Up @@ -68,14 +68,19 @@ Date.prototype.getWeek = function() {
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
}

function difference(object1, object2) {
function difference(object1, object2, depth = 0, maxDepth = 10) {
object1 = object1 || {};
object2 = object2 || {};
var changes = {};

if (depth > maxDepth) {
return changes;
}

_.uniq(Object.keys(object1).concat(Object.keys(object2))).forEach(function(name) {
if (name in object1 && name in object2) {
if (_.isObject(object1[name]) && !_.isArray(object1[name]) && _.isObject(object2[name]) && !_.isArray(object2[name])) {
var diff = difference(object1[name], object2[name]);
var diff = difference(object1[name], object2[name], depth + 1, maxDepth);
if (!_.isEmpty(diff)) {
changes[name] = diff;
}
Expand Down
10 changes: 10 additions & 0 deletions public/assets/tests/qunit/core.js
Expand Up @@ -657,6 +657,16 @@ QUnit.test('difference', assert => {

item = difference(undefined, {})
assert.deepEqual(item, {})

try {
a = { a: { a: 1 } }
b = { b: { b: a } }
a.a.a = b
item = difference(a, a)
assert.deepEqual(item, {})
} catch(error) {
assert.deepEqual(false, true, 'recursion failed: ' + error)
}
});

QUnit.test('auth - not existing user', assert => {
Expand Down

0 comments on commit 81448d2

Please sign in to comment.