From c90f8415b38e01242462ac47a77691defca8f6c5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 10 Aug 2022 01:33:13 -0400 Subject: [PATCH] Improve test for `event-title` substitution And add comments Follow-up to 20d0f103f --- chrome/content/zotero/xpcom/style.js | 7 +++++++ test/tests/styleTest.js | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index cc103e7452..232f442246 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -799,10 +799,16 @@ Zotero.Style.prototype.getCiteProc = function(locale, format, automaticJournalAb } }; +/** + * Temporarily substitute `event-title` for `event` + * + * Until https://github.com/citation-style-language/styles/issues/6151 + */ Zotero.Style.prototype._eventToEventTitle = function (xml) { var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser); var doc = parser.parseFromString(xml, "text/xml"); + // Ignore styles that already include `event-title` if (doc.querySelector('[variable*="event-title"]')) { return xml; } @@ -813,6 +819,7 @@ Zotero.Style.prototype._eventToEventTitle = function (xml) { var changed = false; for (let elem of elems) { let variable = elem.getAttribute('variable'); + // Must be "event" or "event foo", not, say, "event-place" if (!/event( |$)/.test(variable)) { continue; } diff --git a/test/tests/styleTest.js b/test/tests/styleTest.js index e493a3bd7d..a16b3b4429 100644 --- a/test/tests/styleTest.js +++ b/test/tests/styleTest.js @@ -98,7 +98,9 @@ describe("Zotero.Styles", function() { - + + + @@ -113,6 +115,7 @@ describe("Zotero.Styles", function() { } ); item.setField('conferenceName', 'Conference'); + item.setField('place', 'Place'); await item.saveTx(); }); @@ -121,7 +124,7 @@ describe("Zotero.Styles", function() { var cslEngine = style.getCiteProc('en-US', 'text'); var text = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text"); cslEngine.free(); - assert.equal(text, 'Conference - Conference\n'); + assert.equal(text, 'Conference - Conference - Place\n'); }); }); });