seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
76 stars 39 forks source link

apa.csl, sort, Undefined property: stdClass::$status in Style\Sort\Sort.php on line 126 #157

Open glorieux-f opened 1 year ago

glorieux-f commented 1 year ago

Please follow the general troubleshooting steps first:

Bug reports:

In apa.csl#L285 we can read « APA sorts 1. no-date items, 2. items with dates, 3. in-press (status) items ». Your sort algorithm seems (sorry, I have not dig it fully) to suppose that the status property is always available. « Undefined property: stdClass::$status in Style\Sort\Sort.php on line 126 ».

Used CSL stylesheet:

apa.csl

Used CSL metadata

Minimum CSL data to reproduce the bug.

[
    {
        "id": "http://zotero.org/groups/5048422/items/E9V3HGZ9",
        "type": "article-journal",
        "title": "title",
        "author": [
            {
                "family": "Doe",
                "given": "John"
            }
        ],
        "issued": {
            "date-parts": [
                [
                    "1911"
                ]
            ]
        }
    },
    {
        "id": "http://zotero.org/groups/5048422/items/KFWGRZP2",
        "type": "article-journal",
        "title": "title",
        "author": [
            {
                "family": "Doe",
                "given": "John"
            }
        ],
        "issued": {
            "date-parts": [
                [
                    "1911"
                ]
            ]
        }
    }
]
glorieux-f commented 1 year ago

Other bug in Sort, l. 116, if a sort variable is not available.

rob-zivtech commented 7 months ago

Getting this too: Warning: Undefined property: stdClass::$status in /app/vendor/seboettg/citeproc-php/src/Style/Sort/Sort.php on line 126 Deprecated: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /app/vendor/seboettg/citeproc-php/src/Style/Sort/Sort.php on line 126

Line 126 is:

 $sortKey = mb_strtolower(strip_tags($dataItem->{$variable}));

I would recommend adding defensive code:

 $sortKey = '';
if(isset($dataItem->{$variable}) && is_string($dataItem->{$variable})) {
    $sortKey = mb_strtolower(strip_tags($dataItem->{$variable}));
}