Ignore sanitization changes when comparing notes in conflict
Until we have a consistent way of sanitizing HTML on client and server, account for differences manually. More differences between HTMLPurifier and TinyMCE should be added as necessary.
This commit is contained in:
parent
6f04b34d59
commit
d8025be676
2 changed files with 59 additions and 0 deletions
|
@ -321,6 +321,13 @@ Zotero.DataObjectUtilities = {
|
|||
}
|
||||
break;
|
||||
|
||||
case 'note':
|
||||
let change = this._htmlDiff(field, val1, val2);
|
||||
if (change) {
|
||||
changeset.push(change);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
var changed = val1 !== val2;
|
||||
if (changed) {
|
||||
|
@ -449,6 +456,45 @@ Zotero.DataObjectUtilities = {
|
|||
return changeset;
|
||||
},
|
||||
|
||||
_htmlDiff: function (field, html1, html2 = "") {
|
||||
if (html1 == "" && html2 != "") {
|
||||
return {
|
||||
field,
|
||||
op: "add",
|
||||
value: html2
|
||||
};
|
||||
}
|
||||
if (html1 != "" && html2 == "") {
|
||||
return {
|
||||
field,
|
||||
op: "delete"
|
||||
};
|
||||
}
|
||||
|
||||
// Until we have a consistent way of sanitizing HTML on client and server, account for differences
|
||||
var mods = [
|
||||
['<p> </p>', '<p>\u00a0</p>']
|
||||
];
|
||||
var a = html1;
|
||||
var b = html2;
|
||||
for (let mod of mods) {
|
||||
a = a.replace(new RegExp(mod[0], 'g'), mod[1]);
|
||||
b = b.replace(new RegExp(mod[0], 'g'), mod[1]);
|
||||
}
|
||||
if (a != b) {
|
||||
Zotero.debug("HTML diff:");
|
||||
Zotero.debug(a);
|
||||
Zotero.debug(b);
|
||||
return {
|
||||
field,
|
||||
op: "modify",
|
||||
value: html2
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
_tagsDiff: function (data1, data2 = []) {
|
||||
var changeset = [];
|
||||
outer:
|
||||
|
|
|
@ -104,6 +104,19 @@ describe("Zotero.DataObjectUtilities", function() {
|
|||
})
|
||||
})
|
||||
|
||||
describe("notes", function () {
|
||||
it("should ignore sanitization changes", function* () {
|
||||
var json1 = {
|
||||
note: "<p> </p>"
|
||||
};
|
||||
var json2 = {
|
||||
note: "<p> </p>"
|
||||
};
|
||||
var changes = Zotero.DataObjectUtilities.diff(json1, json2);
|
||||
assert.lengthOf(changes, 0);
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
// Relations
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue