Skip to content

Commit

Permalink
Avoid crashing on citations with no items
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Dec 18, 2019
1 parent d60a0d5 commit 978981a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/api_cite.js
Expand Up @@ -159,7 +159,7 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre,

// attach the sorted list to the citation item
citation.sortedItems = sortedItems;

// build reconstituted citations list in current document order
var citationByIndex = [];
var citationById = {};
Expand Down Expand Up @@ -487,10 +487,15 @@ CSL.Engine.prototype.processCitationCluster = function (citation, citationsPre,
if (prevCitation.properties.mode === "author-only" && j > 1) {
old_last_id_offset = 2;
}
oldlastid = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1].id;
oldlastxloc = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1]["locator-extra"];
if (prevCitation.sortedItems[0].slice(-1)[0].legislation_id) {
oldlastid = prevCitation.sortedItems[0].slice(-1)[0].legislation_id;
var adjusted_offset = (j - old_last_id_offset);
if (citations[adjusted_offset].sortedItems.length) {
oldlastid = citations[adjusted_offset].sortedItems.slice(-1)[0][1].id;
oldlastxloc = citations[j - old_last_id_offset].sortedItems.slice(-1)[0][1]["locator-extra"];
}
if (prevCitation.sortedItems.length) {
if (prevCitation.sortedItems[0].slice(-1)[0].legislation_id) {
oldlastid = prevCitation.sortedItems[0].slice(-1)[0].legislation_id;
}
}
}
if (j > 0 && k === 0 && prevCitation.properties.noteIndex !== thisCitation.properties.noteIndex) {
Expand Down

0 comments on commit 978981a

Please sign in to comment.