seboettg / citeproc-php

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

Bug in StringHelper::capitalizeForTitle() #105

Closed cambraca closed 2 years ago

cambraca commented 3 years ago

Bug report:

The rendered bibliography item for the CSL metadata below is:

  1. braintree/Braintree_php. Braintree; 2021. Accessed June 21, 2021. https://github.com/braintree/braintree_php/blob/d6ce80f7f54abe9972d577173343d1975bc49e77/lib/Braintree/Digest.php

The title should be "Braintree/Braintree_php", starting with an upper case "B", as per this section of the CSL:

  <macro name="title">
    <choose>
      <if type="bill book graphic legal_case legislation motion_picture report song" match="any">
        <text variable="title" font-style="italic" text-case="title"/>
      </if>
      <else>
        <text variable="title"/>
      </else>
    </choose>
  </macro>

I traced it to the StringHelper::capitalizeForTitle function, and tested it directly:

StringHelper::capitalizeForTitle('foo bar') === 'Foo Bar' // correct
StringHelper::capitalizeForTitle('foo/bar') === 'foo/Bar' // incorrect

Used CSL stylesheet:

american-medical-association.csl

Used CSL metadata

[
    {
        "id": "item-1",
        "type": "book",
        "abstract": "Braintree PHP library",
        "genre": "PHP",
        "note": "original-date: 2010-02-26T00:46:58Z",
        "publisher": "Braintree",
        "source": "GitHub",
        "title": "braintree\/braintree_php",
        "URL": "https:\/\/github.com\/braintree\/braintree_php\/blob\/d6ce80f7f54abe9972d577173343d1975bc49e77\/lib\/Braintree\/Digest.php",
        "accessed": {
            "date-parts": [
                [
                    "2021",
                    6,
                    21
                ]
            ]
        },
        "issued": {
            "date-parts": [
                [
                    "2021",
                    6,
                    21
                ]
            ]
        }
    }
]