Skip to content

Commit

Permalink
Merge pull request #454 from GlazerMann/patch-16
Browse files Browse the repository at this point in the history
Convert page range to pages if end=start
  • Loading branch information
Martin R. Smith committed Aug 1, 2018
2 parents 7e3ff09 + 6a8f879 commit 9c5e464
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,15 @@ protected function tidy() {
" parameter" . tag());
$p->val = mb_ereg_replace(TO_EN_DASH, EN_DASH, $p->val);
}
if ( (mb_substr_count($p->val, "") === 1) // Exactly one EN_DASH.
&& (mb_stripos($p->val, "http") === FALSE)) {
$the_dash = mb_strpos($p->val, ""); // ALL must be mb_ functions because of long dash
$part1 = mb_substr($p->val, 0, $the_dash);
$part2 = mb_substr($p->val, $the_dash + 1);
if ($part1 === $part2) {
$p->val = $part1;
}
}
break;
case 'coauthor': case 'coauthors': // Commonly left there and empty and deprecated
if ($this->blank($pmatch[1])) $this->forget($pmatch[1]);
Expand Down
13 changes: 10 additions & 3 deletions tests/phpunit/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,20 @@ public function testConvertJournalToBook() {
public function testPagesDash() {
$text = '{{cite journal|pages=1-2|title=do change}}';
$expanded = $this->process_citation($text);
$this->assertEquals('1–2',$expanded->get('pages'));
$this->assertEquals('1–2', $expanded->get('pages'));
$text = '{{cite journal|at=1-2|title=do not change}}';
$expanded = $this->process_citation($text);
$this->assertEquals('1-2',$expanded->get('at'));
$this->assertEquals('1-2', $expanded->get('at'));
$text = '{{cite journal|pages=[http://bogus.bogus/1–2/ 1–2]|title=do not change }}';
$expanded = $this->process_citation($text);
$this->assertEquals('[http://bogus.bogus/1–2/ 1–2]',$expanded->get('pages'));
$this->assertEquals('[http://bogus.bogus/1–2/ 1–2]', $expanded->get('pages'));
}

public function testCollapseRanges() {
$text = '{{cite journal|pages=1233-1233|year=1999-1999}}';
$expanded = $this->process_citation($text);
$this->assertEquals('1233', $expanded->get('pages'));
$this->assertEquals('1999', $expanded->get('year'));
}

public function testDoNotAddYearIfDate() {
Expand Down

0 comments on commit 9c5e464

Please sign in to comment.