diff --git a/packages/ejson/ejson.js b/packages/ejson/ejson.js index a4670297d2..25efbc761d 100644 --- a/packages/ejson/ejson.js +++ b/packages/ejson/ejson.js @@ -486,10 +486,16 @@ EJSON.equals = (a, b, options) => { return b.equals(a, options); } - if (a instanceof Array) { - if (!(b instanceof Array)) { - return false; - } + // Array.isArray works across iframes while instanceof won't + const aIsArray = Array.isArray(a); + const bIsArray = Array.isArray(b); + + // if not both or none are array they are not equal + if (aIsArray !== bIsArray) { + return false; + } + + if (aIsArray && bIsArray) { if (a.length !== b.length) { return false; } diff --git a/packages/ejson/ejson_tests.js b/packages/ejson/ejson_tests.js index eb246742c6..aaad7aa103 100644 --- a/packages/ejson/ejson_tests.js +++ b/packages/ejson/ejson_tests.js @@ -44,6 +44,14 @@ Tinytest.add('ejson - some equality tests', test => { test.isFalse(EJSON.equals({a: 1, b: 2, c: 3}, {a: 1, c: 3, b: 4})); test.isFalse(EJSON.equals({a: {}}, {a: {b: 2}})); test.isFalse(EJSON.equals({a: {b: 2}}, {a: {}})); + // XXX: Object and Array were previously mistaken, which is why + // we add some extra tests for them here + test.isTrue(EJSON.equals([1, 2, 3, 4, 5], [1, 2, 3, 4, 5])); + test.isFalse(EJSON.equals([1, 2, 3, 4, 5], [1, 2, 3, 4])); + test.isFalse(EJSON.equals([1,2,3,4], {0: 1, 1: 2, 2: 3, 3: 4})); + test.isFalse(EJSON.equals({0: 1, 1: 2, 2: 3, 3: 4}, [1,2,3,4])); + test.isFalse(EJSON.equals({}, [])); + test.isFalse(EJSON.equals([], {})); }); Tinytest.add('ejson - equality and falsiness', test => { diff --git a/packages/mongo/oplog_v2_converter.js b/packages/mongo/oplog_v2_converter.js index c7576087c5..42c67703e7 100644 --- a/packages/mongo/oplog_v2_converter.js +++ b/packages/mongo/oplog_v2_converter.js @@ -94,12 +94,11 @@ function flattenObject(ob) { for (const i in ob) { if (!ob.hasOwnProperty(i)) continue; - if (typeof ob[i] == 'object' && ob[i] !== null) { + if (!Array.isArray(ob[i]) && typeof ob[i] == 'object' && ob[i] !== null) { const flatObject = flattenObject(ob[i]); - if(Object.keys(flatObject).length === 0) { return ob; } - for (const x in flatObject) { - if (!flatObject.hasOwnProperty(x)) continue; - + let objectKeys = Object.keys(flatObject); + if(objectKeys.length === 0) { return ob; } + for (const x of objectKeys) { toReturn[i + '.' + x] = flatObject[x]; } } else { diff --git a/packages/mongo/oplog_v2_converter_tests.js b/packages/mongo/oplog_v2_converter_tests.js index 602e82cb6f..5a230989d1 100644 --- a/packages/mongo/oplog_v2_converter_tests.js +++ b/packages/mongo/oplog_v2_converter_tests.js @@ -98,6 +98,12 @@ Tinytest.add('oplog - v2/v1 conversion', function(test) { JSON.stringify({ $v: 2, $set: { 'services.resume.loginTokens': [] } }) ); + const entry91 = { "$v" : 2, "diff" : { "i" : { "tShirt" : { "sizes" : [ "small", "medium", "large" ] } } } }; + test.equal( + JSON.stringify(oplogV2V1Converter(entry91)), + JSON.stringify({ $v: 2, $set: { "tShirt.sizes" : [ "small", "medium", "large" ] } }) + ); + const entry10 = { $v: 2, $set: { diff --git a/packages/mongo/package.js b/packages/mongo/package.js index 55aae6cdc3..3bc6b4e36e 100644 --- a/packages/mongo/package.js +++ b/packages/mongo/package.js @@ -9,7 +9,7 @@ Package.describe({ summary: "Adaptor for using MongoDB and Minimongo over DDP", - version: '1.14.1' + version: '1.14.2' }); Npm.depends({