Fix "string is undefined" export error

Regression from a549a64de9
This commit is contained in:
Dan Stillman 2019-11-29 01:50:43 -07:00
parent 4d7062fc43
commit fbb54a7621
2 changed files with 28 additions and 1 deletions

View file

@ -263,7 +263,9 @@ Zotero.Date = new function(){
order: '' order: ''
}; };
string = Zotero.Utilities.trimInternal(string.toString()); if (typeof string == 'string' || typeof string == 'number') {
string = Zotero.Utilities.trimInternal(string.toString());
}
// skip empty things // skip empty things
if(!string) { if(!string) {

View file

@ -157,6 +157,31 @@ describe("Zotero.Date", function() {
}) })
describe("#strToDate()", 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* () { it("should work in translator sandbox", function* () {
var item = createUnsavedDataObject('item'); var item = createUnsavedDataObject('item');
item.libraryID = Zotero.Libraries.userLibraryID; item.libraryID = Zotero.Libraries.userLibraryID;