seboettg / citeproc-php

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

Page numbering issue #60

Closed asmecher closed 5 years ago

asmecher commented 5 years ago

Please follow the general troubleshooting steps first:

Bug reports:

Page number parsing seems broken

Used CSL stylesheet:

Vancouver format: https://github.com/pkp/citationStyleLanguage/blob/master/citation-styles/vancouver.csl

Used sample code

<?php

require_once('lib/vendor/autoload.php');
use Seboettg\CiteProc\CiteProc;

$citationData = new stdClass();
$citationData->type = 'article-journal';
$citationData->id = 123;
$citationData->title = 'My Article';
$citationData->{'container-title'} = 'Journal of ABCs';
$citationData->{'container-title-short'} = 'JABC';
$citationData->volume = 1;
$citationData->issue = 1;
$citationData->section = 'Section Title';
$citationData->page = '3-10';

$citeProc = new CiteProc(file_get_contents('citation-styles/vancouver.csl'), 'en-US');
$citation = $citeProc->render(array($citationData), 'bibliography');

echo $citation;

Expected output

<div class="csl-bib-body">
  <div class="csl-entry"><div class="csl-left-margin">1. </div><div class="csl-right-inline">My Article. JABC. 1(1):3-10. </div></div>

Received output

PHP Notice:  Uninitialized string offset: 1 in /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Util/PageHelper.php on line 63
PHP Stack trace:
PHP   1. {main}() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/test.php:0
PHP   2. Seboettg\CiteProc\CiteProc->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/test.php:18
PHP   3. Seboettg\CiteProc\CiteProc->bibliography() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/CiteProc.php:183
PHP   4. Seboettg\CiteProc\Style\Bibliography->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/CiteProc.php:137
PHP   5. Seboettg\CiteProc\Rendering\Layout->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Style/Bibliography.php:70
PHP   6. Seboettg\CiteProc\Rendering\Layout->renderSingle() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Layout.php:91
PHP   7. Seboettg\CiteProc\Rendering\Group->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Layout.php:126
PHP   8. Seboettg\CiteProc\Rendering\Group->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Group.php:104
PHP   9. Seboettg\CiteProc\Rendering\Text->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Group.php:104
PHP  10. Seboettg\CiteProc\Rendering\Text->renderMacro() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Text.php:111
PHP  11. Seboettg\CiteProc\Style\Macro->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Text.php:254
PHP  12. Seboettg\CiteProc\Rendering\Choose\Choose->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Style/Macro.php:86
PHP  13. Seboettg\CiteProc\Rendering\Choose\ChooseIf->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Choose/Choose.php:73
PHP  14. Seboettg\CiteProc\Rendering\Text->render() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Choose/ChooseIf.php:88
PHP  15. Seboettg\CiteProc\Rendering\Text->renderPage() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Text.php:100
PHP  16. Seboettg\CiteProc\Util\PageHelper::processPageRangeFormats() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Rendering/Text.php:150
PHP  17. Seboettg\CiteProc\Util\PageHelper::renderMinimal() /home/asmecher/git/ojs-stable-3_1_1/plugins/generic/citationStyleLanguage/lib/vendor/seboettg/citeproc-php/src/Seboettg/CiteProc/Util/PageHelper.php:30
<div class="csl-bib-body">
  <div class="csl-entry"><div class="csl-left-margin">1. </div><div class="csl-right-inline">My Article. JABC. 1(1):3-0. </div></div>

Note the truncated page numbering in the Received Output: 3-0. This should be 3-10.

seboettg commented 5 years ago

Thank you for this bug report! In release 2.1.6 this issue should be solved.

seboettg commented 5 years ago

please reopen this issue, if the issue reappears.

asmecher commented 5 years ago

Will do -- thanks, @seboettg!

asmecher commented 5 years ago

I'm still getting odd-looking citation, e.g. piping in

$citationData->page = '39-47';

...and using citation-styles/vancouver.csl gives me...

My Article. JABC. 1(1):39-7.

instead of

My Article. JABC. 1(1):39-47.

I think the problem is that the call to renderMinimal in https://github.com/seboettg/citeproc-php/blob/master/src/Seboettg/CiteProc/Util/PageHelper.php#L30 should specify a limit of 0 rather than letting it default to 1, no?

This should fix it (see also the test case): https://github.com/seboettg/citeproc-php/pull/66