diff --git a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js index 7e0ca16e37..fc7c2569c2 100644 --- a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js +++ b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js @@ -275,7 +275,7 @@ Zotero.DataObjectUtilities = { var pred2 = Object.keys(data2); pred2.sort(); if (!Zotero.Utilities.arrayEquals(pred1, pred2)) return true; - for (let pred in pred1) { + for (let pred of pred1) { let vals1 = typeof data1[pred] == 'string' ? [data1[pred]] : data1[pred]; let vals2 = (!data2[pred] || data2[pred] === '') ? [] diff --git a/test/tests/dataObjectUtilitiesTest.js b/test/tests/dataObjectUtilitiesTest.js index 16a5fa89fd..ab099a204a 100644 --- a/test/tests/dataObjectUtilitiesTest.js +++ b/test/tests/dataObjectUtilitiesTest.js @@ -59,6 +59,42 @@ describe("Zotero.DataObjectUtilities", function() { // place was already empty, so it shouldn't be included assert.notProperty(obj, 'place'); }); + + it("shouldn't include relations that haven't changed", function () { + var patchBase = { + title: "Old Title", + relations: { + "mendeleyDB:documentUUID": "6b97abe6-8e23-4471-b963-234cf26808b9" + } + }; + var obj = { + title: "New Title", + relations: { + "mendeleyDB:documentUUID": "6b97abe6-8e23-4471-b963-234cf26808b9" + } + } + obj = Zotero.DataObjectUtilities.patch(patchBase, obj); + assert.notProperty(obj, 'relations'); + }); + + it("shouldn't include relations that only switched from string to array", function () { + var patchBase = { + title: "Old Title", + relations: { + "mendeleyDB:documentUUID": "6b97abe6-8e23-4471-b963-234cf26808b9" + } + }; + var obj = { + title: "New Title", + relations: { + "mendeleyDB:documentUUID": [ + "6b97abe6-8e23-4471-b963-234cf26808b9" + ] + } + } + obj = Zotero.DataObjectUtilities.patch(patchBase, obj); + assert.notProperty(obj, 'relations'); + }); }) describe("#diff()", function () {