Remove one unnecessary LogicException from ReferenceStack

This exception was introduced very late in the patch I38c9929. It
already caused trouble. This here is essentially a revert. It restores
the previous behavior where this edge-case was silently ignored. The
worst thing that can happen is that appendText() creates an incomplete
entry in the $this->refs array, which will be rendered at the end. The
user can see it then.

As of now we are not aware of a code path where this would even be
possible. Still this does make the code *more* robust by not making it
explode, but give the user something they can work with.

Bug: T243221
Change-Id: I2e2d29bbd557090981903fcc2ece8796fafa4aa4
This commit is contained in:
Thiemo Kreuz 2020-01-28 16:10:49 +01:00
parent 8105f64740
commit 0fda08b25a
3 changed files with 2 additions and 17 deletions

View file

@ -409,7 +409,7 @@ class Cite {
*
* @param Parser $parser
* @param ?string $text Raw, untrimmed wikitext content of the <references> tag, if any
* @param string[] $argv Arguments as given in <references name=>, already trimmed
* @param string[] $argv Arguments as given in <references >, already trimmed
*
* @return string|false False in case a <references> tag is not allowed in the current context
*/
@ -429,7 +429,7 @@ class Cite {
*
* @param Parser $parser
* @param ?string $text Raw, untrimmed wikitext content of the <references> tag, if any
* @param string[] $argv Arguments as given in <references name=>, already trimmed
* @param string[] $argv Arguments as given in <references >, already trimmed
*
* @return string HTML
*/

View file

@ -424,10 +424,6 @@ class ReferenceStack {
* @param string $text
*/
public function appendText( string $group, string $name, string $text ) {
if ( !isset( $this->refs[$group][$name] ) ) {
throw new LogicException( "Unknown ref \"$name\" in group \"$group\"" );
}
if ( isset( $this->refs[$group][$name]['text'] ) ) {
$this->refs[$group][$name]['text'] .= $text;
} else {

View file

@ -1050,22 +1050,11 @@ class ReferenceStackTest extends \MediaWikiUnitTestCase {
$this->assertSame( [], $stack->getGroupRefs( 'empty' ) );
}
/**
* @covers ::appendText
*/
public function testAppendText_failure() {
$stack = $this->newStack();
$this->expectException( LogicException::class );
$stack->appendText( 'group', 'name', 'the-text' );
}
/**
* @covers ::appendText
*/
public function testAppendText() {
$stack = $this->newStack();
$stack->refs = [ 'group' => [ 'name' => [] ] ];
$stack->appendText( 'group', 'name', 'set' );
$this->assertSame( [ 'text' => 'set' ], $stack->refs['group']['name'] );