From 91ca6d2ba6cbe6256a0adc97f3d3de05a9bcb833 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 3 Apr 2020 18:11:32 -0400 Subject: [PATCH] extraToCSL(): Fix "zoteroField[1] is undefined" on single-character field E.g., "a:" on a line https://forums.zotero.org/discussion/82286/new-line-in-extra-field-induces-error-during-bibliography-generation --- chrome/content/zotero/xpcom/cite.js | 2 +- test/tests/citeTest.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index 00e6540fdc..04aded289a 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -413,7 +413,7 @@ Zotero.Cite = { // convert to its associated CSL field var zoteroField = originalField.replace(/ ([A-Z])/, '$1'); // If second character is lowercase (so not an acronym), lowercase first letter too - if (zoteroField[1] == zoteroField[1].toLowerCase()) { + if (zoteroField[1] && zoteroField[1] == zoteroField[1].toLowerCase()) { zoteroField = zoteroField[0].toLowerCase() + zoteroField.substr(1); } if (Zotero.Schema.CSL_FIELD_MAPPINGS_REVERSE[zoteroField]) { diff --git a/test/tests/citeTest.js b/test/tests/citeTest.js index a5a5e3579f..acbf69c852 100644 --- a/test/tests/citeTest.js +++ b/test/tests/citeTest.js @@ -41,5 +41,10 @@ describe("Zotero.Cite", function () { var str2 = 'DOI: 10.0/abc'; assert.equal(Zotero.Cite.extraToCSL(str1), str2); }); + + it("should handle a single-character field name", function () { + var str = 'a: '; + assert.equal(Zotero.Cite.extraToCSL(str), str); + }); }); });