seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
73 stars 38 forks source link

htmlspecialchars(): Argument #1 ($string) must be of type string, array given #184

Open hktang opened 5 months ago

hktang commented 5 months ago

Hi, I run into a TypeError when rendering BibTex format. Could you point me to where I should check?

General troubleshooting steps:

Bug reports:

  1. I retrieve citeproc-JSON metadata from DOI content negotiation.
  2. I feed it into citeProc and select "bibtex" as the output format.
  3. I receive the following error message for some publications:
htmlspecialchars(): Argument #1 ($string) must be of type string, array given in htmlspecialchars() 
(line 237 of /var/www/html/vendor/seboettg/citeproc-php/src/Rendering/Text.php).

For some other (less complex?) metadata, the bibtex output renders successfully.

Used CSL stylesheet:

bibtex.csl

Used CSL metadata

Below is the metadata I used (abstract and references removed).

[{
    "indexed": {
        "date-parts": [
            [
                2023,
                11,
                9
            ]
        ],
        "date-time": "2023-11-09T00:41:10Z",
        "timestamp": 1699490470291
    },
    "reference-count": 54,
    "publisher": "MDPI AG",
    "issue": "22",
    "license": [
        {
            "start": {
                "date-parts": [
                    [
                        2023,
                        11,
                        8
                    ]
                ],
                "date-time": "2023-11-08T00:00:00Z",
                "timestamp": 1699401600000
            },
            "content-version": "vor",
            "delay-in-days": 0,
            "URL": "https:\/\/creativecommons.org\/licenses\/by\/4.0\/"
        }
    ],
    "funder": [
        {
            "name": "Institute of Global Environmental Strategies, Hayama, Japan"
        }
    ],
    "content-domain": {
        "domain": [],
        "crossmark-restriction": false
    },
    "abstract": "",
    "DOI": "10.3390\/su152215733",
    "type": "journal-article",
    "created": {
        "date-parts": [
            [
                2023,
                11,
                8
            ]
        ],
        "date-time": "2023-11-08T12:02:05Z",
        "timestamp": 1699444925000
    },
    "page": "15733",
    "source": "Crossref",
    "is-referenced-by-count": 0,
    "title": "Monitoring G20 Countries\u2019 SDG Implementation Policies and Budgets Reported in Their Voluntary National Reviews (VNRs)",
    "prefix": "10.3390",
    "volume": "15",
    "author": [
        {
            "ORCID": "http:\/\/orcid.org\/0000-0002-1651-7843",
            "authenticated-orcid": false,
            "given": "Mark",
            "family": "Elder",
            "sequence": "first",
            "affiliation": [
                {
                    "name": "Institute for Global Environmental Strategies, Hayama 240-0115, Japan"
                }
            ]
        },
        {
            "ORCID": "http:\/\/orcid.org\/0000-0003-0671-5026",
            "authenticated-orcid": false,
            "given": "Elli",
            "family": "Newman",
            "sequence": "additional",
            "affiliation": [
                {
                    "name": "Energy Innovation, San Francisco, CA 94111, USA"
                }
            ]
        }
    ],
    "member": "1968",
    "published-online": {
        "date-parts": [
            [
                2023,
                11,
                8
            ]
        ]
    },
    "container-title": "Sustainability",
    "original-title": [],
    "language": "en",
    "link": [
        {
            "URL": "https:\/\/www.mdpi.com\/2071-1050\/15\/22\/15733\/pdf",
            "content-type": "unspecified",
            "content-version": "vor",
            "intended-application": "similarity-checking"
        }
    ],
    "deposited": {
        "date-parts": [
            [
                2023,
                11,
                8
            ]
        ],
        "date-time": "2023-11-08T12:31:10Z",
        "timestamp": 1699446670000
    },
    "score": 1,
    "resource": {
        "primary": {
            "URL": "https:\/\/www.mdpi.com\/2071-1050\/15\/22\/15733"
        }
    },
    "subtitle": [],
    "short-title": [],
    "issued": {
        "date-parts": [
            [
                2023,
                11,
                8
            ]
        ]
    },
    "references-count": 54,
    "journal-issue": {
        "issue": "22",
        "published-online": {
            "date-parts": [
                [
                    2023,
                    11
                ]
            ]
        }
    },
    "alternative-id": [
        "su152215733"
    ],
    "URL": "http:\/\/dx.doi.org\/10.3390\/su152215733",
    "relation": {},
    "ISSN": [
        "2071-1050"
    ],
    "subject": [
        "Management, Monitoring, Policy and Law",
        "Renewable Energy, Sustainability and the Environment",
        "Geography, Planning and Development",
        "Building and Construction"
    ],
    "container-title-short": "Sustainability",
    "published": {
        "date-parts": [
            [
                2023,
                11,
                8
            ]
        ]
    }
}]
hktang commented 5 months ago

I did a couple of more tests by changing the following line so that it outputs serialized data:

https://github.com/seboettg/citeproc-php/blob/4070bdc3ad1c5fa1cfe3887f2db70f281a50e4a7/src/Rendering/Text.php#L237

Then it seems at least the ISSN and Rights elements are passed in as an array. Should I check the DOI content negotiation output, or is it something we can fix by updating the bibtex.csl? I am new to CSL so any suggestion will be appreciated.