From be300ec62b5987a0277aefb36d13fc66e5cbbc40 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 19 Jan 2018 12:57:45 -0500 Subject: [PATCH] Fix startup hang if note is null in database (cherry picked from commit 2194dff7a49f268f66af9a9db525629087ff5215) --- chrome/content/zotero/xpcom/data/items.js | 38 ++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index c71c8532f..2854d61d6 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -415,21 +415,31 @@ Zotero.Items = function() { // Convert non-HTML notes on-the-fly if (note !== "") { - if (!note.substr(0, 36).match(/^
/)) { - note = Zotero.Utilities.htmlSpecialChars(note); - note = Zotero.Notes.notePrefix + '

' - + note.replace(/\n/g, '

') - .replace(/\t/g, '    ') - .replace(/ /g, '  ') - + '

' + Zotero.Notes.noteSuffix; - note = note.replace(/

\s*<\/p>/g, '

 

'); - notesToUpdate.push([item.id, note]); + if (typeof note == 'number') { + note = '' + note; + } + if (typeof note == 'string') { + if (!note.substr(0, 36).match(/^
/)) { + note = Zotero.Utilities.htmlSpecialChars(note); + note = Zotero.Notes.notePrefix + '

' + + note.replace(/\n/g, '

') + .replace(/\t/g, '    ') + .replace(/ /g, '  ') + + '

' + Zotero.Notes.noteSuffix; + note = note.replace(/

\s*<\/p>/g, '

 

'); + notesToUpdate.push([item.id, note]); + } + + // Don't include
wrapper when returning value + let startLen = note.substr(0, 36).match(/^
/)[0].length; + let endLen = 6; // "
".length + note = note.substr(startLen, note.length - startLen - endLen); + } + // Clear null notes + else { + note = ''; + notesToUpdate.push([item.id, '']); } - - // Don't include
wrapper when returning value - let startLen = note.substr(0, 36).match(/^
/)[0].length; - let endLen = 6; // "
".length - note = note.substr(startLen, note.length - startLen - endLen); } item._noteText = note ? note : '';