zepinglee / citeproc-lua

A Lua implementation of the Citation Style Language (CSL)
MIT License
62 stars 7 forks source link

Catch nil in PMID (citeproc-bibtex2csl.lua) #37

Closed bemilton closed 11 months ago

bemilton commented 1 year ago

Describe the bug

Forgive me for not making a PR, but I believe you will be able to code a better solution if this needs patching. The cause may be due to my bib file being dirty rather than this being a bug in the code!

However, I patched citeproc-bibtex2csl.lua:

-  if bib_fields.eprint and string.lower(bib_fields.eprinttype) == "pubmed" and not item.PMID then
-    item.PMID = bib_fields.eprint

To:

+  if type(bib_fields.eprinttype) == "string" then
+    if bib_fields.eprint and string.lower(bib_fields.eprinttype) == "pubmed" and not item.PMID then
+      item.PMID = bib_fields.eprint
+    end
+  else
+    item.PMID = ""
+   end

This will catch bib entries which fail when string.lower(bib_fields.eprinttype) it is of type/value nil not string. This solved an error in my tex document.

zepinglee commented 1 year ago

Thanks for your patch and it makes sense.