From 7ac22dbef29731db06cbe3b94e2fce599f5724b5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 26 Dec 2025 11:05:59 -0500 Subject: [PATCH] Fix creator extraction from Extra Creators shouldn't be extracted if creators of the same type already exist on the item, to follow citeproc-js behavior, but the code to do that was broken. --- .../zotero/xpcom/utilities_internal.js | 6 ++-- test/tests/utilities_internalTest.js | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index ef01e018d2..cafe6dde11 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -1204,11 +1204,11 @@ Zotero.Utilities.Internal = { c.name = value; } if (item) { - let creatorTypeID = Zotero.CreatorTypes.getID(possibleCreatorType); - if (Zotero.CreatorTypes.isValidForItemType(creatorTypeID, itemTypeID) + let possibleCreatorTypeID = Zotero.CreatorTypes.getID(possibleCreatorType); + if (Zotero.CreatorTypes.isValidForItemType(possibleCreatorTypeID, itemTypeID) // Ignore if there are any creators of this type on the item already, // to follow citeproc-js behavior - && !item.getCreators().some(x => x.creatorType == possibleCreatorType)) { + && !item.getCreators().some(x => x.creatorTypeID == possibleCreatorTypeID)) { creators.push(c); return false; } diff --git a/test/tests/utilities_internalTest.js b/test/tests/utilities_internalTest.js index 0e80384254..a4f9a49595 100644 --- a/test/tests/utilities_internalTest.js +++ b/test/tests/utilities_internalTest.js @@ -265,17 +265,6 @@ describe("Zotero.Utilities.Internal", function () { assert.equal(fields.size, 0); }); - it("should extract an author and add it to existing creators", function () { - var item = createUnsavedDataObject('item', { itemType: 'book' }); - item.setCreator(0, { creatorType: 'author', name: 'Foo' }); - var str = 'author: Bar'; - var { fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item); - assert.equal(fields.size, 0); - assert.lengthOf(creators, 1); - assert.equal(creators[0].creatorType, 'author'); - assert.equal(creators[0].name, 'Bar'); - }); - it("should extract a CSL date field", function () { var str = 'issued: 2000'; var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(str); @@ -313,6 +302,26 @@ describe("Zotero.Utilities.Internal", function () { assert.strictEqual(extra, str); }); + it("shouldn't extract a creator if creators of same type already exist", function () { + var item = createUnsavedDataObject('item', { itemType: 'book' }); + item.setCreator(0, { creatorType: 'author', name: 'Foo' }); + var str = 'author: Bar'; + var { fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item); + assert.equal(fields.size, 0); + assert.lengthOf(creators, 0); + }); + + it("should extract a creator if creators of the same type don't exist", function () { + var item = createUnsavedDataObject('item', { itemType: 'book' }); + item.setCreator(0, { creatorType: 'author', name: 'Foo' }); + var str = 'editor: Bar'; + var { fields, creators, extra } = Zotero.Utilities.Internal.extractExtraFields(str, item); + assert.equal(fields.size, 0); + assert.lengthOf(creators, 1); + assert.equal(creators[0].creatorType, 'editor'); + assert.equal(creators[0].name, 'Bar'); + }); + it("should extract the citeproc-js cheater syntax", function () { var issued = '{:number-of-pages:11}\n{:issued:2014}'; var { fields, extra } = Zotero.Utilities.Internal.extractExtraFields(issued);