From fbb54a762188b71dd7257460d46d05512b5d5bc8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 29 Nov 2019 01:50:43 -0700 Subject: [PATCH] Fix "string is undefined" export error Regression from a549a64de93 --- chrome/content/zotero/xpcom/date.js | 4 +++- test/tests/dateTest.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index ec36d83a72..189ad0b790 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -263,7 +263,9 @@ Zotero.Date = new function(){ order: '' }; - string = Zotero.Utilities.trimInternal(string.toString()); + if (typeof string == 'string' || typeof string == 'number') { + string = Zotero.Utilities.trimInternal(string.toString()); + } // skip empty things if(!string) { diff --git a/test/tests/dateTest.js b/test/tests/dateTest.js index 4330f94f10..eb7eec8036 100644 --- a/test/tests/dateTest.js +++ b/test/tests/dateTest.js @@ -157,6 +157,31 @@ describe("Zotero.Date", function() { }) describe("#strToDate()", function () { + it("should return object without date parts for null", function () { + var o = Zotero.Date.strToDate(null); + assert.notProperty(o, 'year'); + }); + + it("should return object without date parts for undefined", function () { + var o = Zotero.Date.strToDate(); + assert.notProperty(o, 'year'); + }); + + it("should return object without date parts for false", function () { + var o = Zotero.Date.strToDate(false); + assert.notProperty(o, 'year'); + }); + + it("should return object without date parts for empty string", function () { + var o = Zotero.Date.strToDate(''); + assert.notProperty(o, 'year'); + }); + + it("should return object without date parts for blank string", function () { + var o = Zotero.Date.strToDate(' '); + assert.notProperty(o, 'year'); + }); + it("should work in translator sandbox", function* () { var item = createUnsavedDataObject('item'); item.libraryID = Zotero.Libraries.userLibraryID;