diff --git a/Template.php b/Template.php index 80baac3b7f..e4a4a1fcb7 100644 --- a/Template.php +++ b/Template.php @@ -3750,6 +3750,12 @@ public function tidy_parameter(string $param) : void { if (in_array(strtolower($param), ['series', 'journal', 'newspaper']) && $this->has($param)) { $this->set($param, safe_preg_replace('~[™|®]$~u', '', $this->get($param))); // remove trailing TM/(R) } + if (in_array(str_replace(array('-','0','1','2','3','4','5','6','7','8','9'), '', strtolower($param)), ['authorlink', 'chapterlink', 'contributorlink', + 'editorlink', 'episodelink', 'interviewerlink', 'inventorlink', 'serieslink', + 'subjectlink', 'titlelink', 'translatorlink']) && $this->has($param) && (stripos($this->get($param), 'http') === FALSE)) { + $this->set($param, safe_preg_replace('~_~u', ' ', $this->get($param))); + } + if (!preg_match('~^(\D+)(\d*)(\D*)$~', $param, $pmatch)) { report_minor_error("Unrecognized parameter name format in " . echoable($param)); // @codeCoverageIgnore return; // @codeCoverageIgnore diff --git a/tests/phpunit/TemplateTest2.php b/tests/phpunit/TemplateTest2.php index 5b02753806..0f2cb4d5df 100644 --- a/tests/phpunit/TemplateTest2.php +++ b/tests/phpunit/TemplateTest2.php @@ -4674,6 +4674,16 @@ public function testBadChapterStays() : void { $expanded = $this->process_citation($text); $this->assertSame('cite journal', $expanded->wikiname()); $this->assertSame('Chope, His Honour Robert Charles, (26 June 1913–17 Oct. 1988), a Circuit Judge (Formerly Judge of County Courts), 1965–85', $expanded->get2('chapter')); - } + } + + public function testRemoveLinkUnderscores() : void { + $text = "{{cite journal|author-link3=A_X}}"; + $expanded = $this->process_citation($text); + $this->assertSame('A X', $expanded->get3('author-link3')); + + $text = "{{cite journal|author-link3=A_X http}}"; + $expanded = $this->process_citation($text); + $this->assertSame('A_X http', $expanded->get3('author-link3')); + } }