Fix "c1 is undefined" sync CR error

This commit is contained in:
Dan Stillman 2019-10-09 18:29:04 -04:00
parent 4e63cfd40e
commit 89672ed0a4
2 changed files with 79 additions and 1 deletions

View file

@ -1486,6 +1486,10 @@ Zotero.Sync.Data.Local = {
for (let i = 0; i < changeset1.length; i++) {
for (let j = 0; j < changeset2.length; j++) {
let c1 = changeset1[i];
// If we've removed all local changes, keep remaining remote changes
if (!c1) {
break;
}
let c2 = changeset2[j];
if (c1.field != c2.field) {
continue;
@ -1507,6 +1511,9 @@ Zotero.Sync.Data.Local = {
if (c1.op == 'member-add' && c2.op == 'member-add'
&& c1.value.tag === c2.value.tag) {
changeset1.splice(i--, 1);
// We're in the inner loop without an incrementor for i, so don't go
// below 0
if (i < 0) i = 0;
changeset2.splice(j--, 1);
if (c1.value.type > 0) {
changeset2.push({

View file

@ -2191,7 +2191,78 @@ describe("Zotero.Sync.Data.Local", function() {
);
assert.lengthOf(result.conflicts, 0);
})
})
});
describe("tags", function () {
// https://forums.zotero.org/discussion/79429/syncing-error-c1-is-undefined
it("should handle multiple local type 1 and remote type 0", async function () {
var cacheJSON = {
tags: []
};
var json1 = {
tags: [
{
tag: 'C',
type: 1
},
{
tag: 'D',
type: 1
}
]
};
var json2 = {
tags: [
{
tag: 'C'
},
{
tag: 'D'
}
]
};
var result = Zotero.Sync.Data.Local._reconcileChanges(
'tag', cacheJSON, json1, json2
);
assert.lengthOf(result.changes, 4);
assert.sameDeepMembers(
result.changes,
[
{
field: "tags",
op: "member-remove",
value: {
tag: "C",
type: 1
}
},
{
field: "tags",
op: "member-add",
value: {
tag: "C"
}
},
{
field: "tags",
op: "member-remove",
value: {
tag: "D",
type: 1
}
},
{
field: "tags",
op: "member-add",
value: {
tag: "D"
}
}
]
);
});
});
})