Properly check note schema version existence

This commit is contained in:
Martynas Bagdonas 2021-03-03 10:31:04 +02:00 committed by Dan Stillman
parent 8755cf7338
commit d893a02092
3 changed files with 9 additions and 4 deletions

View file

@ -145,6 +145,13 @@ Zotero.Notes = new function() {
}
return doc.body.innerHTML;
};
this.hasSchemaVersion = function (note) {
let parser = Components.classes['@mozilla.org/xmlextras/domparser;1']
.createInstance(Components.interfaces.nsIDOMParser);
let doc = parser.parseFromString(note, 'text/html');
return !!doc.querySelector('body > div[data-schema-version]');
};
};
if (typeof process === 'object' && process + '' === '[object process]') {

View file

@ -88,8 +88,7 @@ class EditorInstance {
placeholder: options.placeholder,
dir: Zotero.dir,
font: this._getFont(),
// TODO: We should avoid hitting `data-schema-version` in note text
hasBackup: note && note.toLowerCase().indexOf('data-schema-version') < 0
hasBackup: note && !Zotero.Notes.hasSchemaVersion(note)
|| !!await Zotero.NoteBackups.getNote(this._item.id)
});
}

View file

@ -34,8 +34,7 @@ Zotero.NoteBackups = {
ensureBackup: async function(item) {
let note = item.note;
// TODO: We should avoid hitting `data-schema-version` in note text
if (note && note.toLowerCase().indexOf('data-schema-version') < 0) {
if (note && !Zotero.Notes.hasSchemaVersion(note)) {
await Zotero.DB.queryAsync("INSERT OR IGNORE INTO noteBackups VALUES (?, ?)", [item.id, item.note]);
}
},