From 045b5f86658a5b49b393ce512b43b88d9b02bc2d Mon Sep 17 00:00:00 2001 From: Jens Kober Date: Tue, 19 Mar 2019 22:43:49 +0100 Subject: [PATCH] getting rid of double spaces --- bibtexbrowser-test.php | 12 ++++++------ bibtexbrowser.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 3b038d2..a7cc24b 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -500,7 +500,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Foo Bar", $authors[2]); - $this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); // test with formatting (first name before) bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', true); @@ -509,7 +509,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Team, Advanced Air and Ground Research", $authors[1]); $this->assertEquals("Bar, Foo", $authors[2]); - $this->assertEquals("Meyer, Heribert; Team, Advanced Air and Ground Research; and Bar, Foo", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer, Heribert; Team, Advanced Air and Ground Research; and Bar, Foo", $entry->getFormattedAuthorsString()); // test with formatting (with initials) formatAuthorInitials bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); @@ -519,7 +519,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer H", $authors[0]); $this->assertEquals("Team AAand GR", $authors[1]); $this->assertEquals("Bar F", $authors[2]); - $this->assertEquals("Meyer H, Team AAand GR, and Bar F", $entry->getFormattedAuthorsString()); + $this->assertEquals("Meyer H, Team AAand GR, and Bar F", $entry->getFormattedAuthorsString()); // test with first_name last_name formatAuthorCanonical bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); @@ -530,7 +530,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Heribert Meyer", $authors[0]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Foo Bar", $authors[2]); - $this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); + $this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString()); // test there is no Oxford comma for only two authors with default options bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false); @@ -766,11 +766,11 @@ class BTBTest extends PHPUnit_Framework_TestCase { $btb->load('bibacid-utf8.bib'); $this->assertEquals(4,count($btb->bibdb['arXiv-1807.05030']->getRawAuthors())); $this->assertEquals(4,count($btb->bibdb['arXiv-1807.05030']->getFormattedAuthorsArray())); - $this->assertEquals("Oscar Luis Vera-Pérez, Benjamin Danglot, Martin Monperrus, and Benoit Baudry",$btb->bibdb['arXiv-1807.05030']->getAuthor()); + $this->assertEquals("Oscar Luis Vera-Pérez, Benjamin Danglot, Martin Monperrus, and Benoit Baudry",$btb->bibdb['arXiv-1807.05030']->getAuthor()); bibtexbrowser_configure('BIBTEXBROWSER_LINK_STYLE','nothing'); bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle'); - $this->assertEquals("Oscar Luis Vera-Pérez, Benjamin Danglot, Martin Monperrus, and Benoit Baudry, \"A Comprehensive Study of Pseudo-tested Methods\", Technical report, arXiv 1807.05030, 2018.\n ",strip_tags($btb->bibdb['arXiv-1807.05030']->toHTML())); + $this->assertEquals("Oscar Luis Vera-Pérez, Benjamin Danglot, Martin Monperrus, and Benoit Baudry, \"A Comprehensive Study of Pseudo-tested Methods\", Technical report, arXiv 1807.05030, 2018.\n ",strip_tags($btb->bibdb['arXiv-1807.05030']->toHTML())); } diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e65c665..f5933a4 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1571,8 +1571,10 @@ class BibEntry { $result .= $authors[$i].$sep; } $lastAuthorSeperator = bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'); + // add Oxford comma if there are more than 2 authors if (count($authors)>2) { $lastAuthorSeperator = $sep.$lastAuthorSeperator; + $lastAuthorSeperator = preg_replace("/ {2,}/", " ", $lastAuthorSeperator); } $result .= $authors[count($authors)-2].$lastAuthorSeperator.$authors[count($authors)-1]; return $result;