Skip to content

Commit

Permalink
Use splice instead of delete to remove attachments
Browse files Browse the repository at this point in the history
Fixes
https://forums.zotero.org/discussion/62917/report-id-985863464-error#latest
@zuphilip -- this is Aurimas's code, but I think I've seen you use
delete for arrays in translators? It's typically not the right
choice. See http://stackoverflow.com/a/5767335
  • Loading branch information
adam3smith committed Oct 23, 2016
1 parent b281814 commit 7948604
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Embedded Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2016-09-08 07:14:24"
"lastUpdated": "2016-10-23 15:17:12"
}

/*
Expand Down Expand Up @@ -479,15 +479,15 @@ function addHighwireMetadata(doc, newItem) {
pdfURL = pdfURL[0].textContent;
//delete any pdf attachments if present
//would it be ok to just delete all attachments??
for(var i=0, n=newItem.attachments.length; i<n; i++) {
for(var i=newItem.attachments.length-1; i>=0; i--) {
if(newItem.attachments[i].mimeType == 'application/pdf') {
delete newItem.attachments[i];
newItem.attachments.splice(i, 1);
}
}

newItem.attachments.push({title:"Full Text PDF", url:pdfURL, mimeType:"application/pdf"});
}

//add snapshot
newItem.attachments.push({document:doc, title:"Snapshot"});

Expand Down Expand Up @@ -1296,4 +1296,4 @@ var testCases = [
]
}
]
/** END TEST CASES **/
/** END TEST CASES **/

0 comments on commit 7948604

Please sign in to comment.