commit d8025be67663628f7f51a363c2efe18f1b943f61
parent 6f04b34d597f97ec5fa548bb4cce6947c7528e64
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 17 May 2016 02:33:53 -0400
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.
Diffstat:
2 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js
@@ -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:
diff --git a/test/tests/dataObjectUtilitiesTest.js b/test/tests/dataObjectUtilitiesTest.js
@@ -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
//