From: Erik Bernhardson Date: Wed, 4 Jun 2014 21:06:03 +0000 (-0700) Subject: Message: Correct output of wfMessage( 'non-existent-msg' )->text() X-Git-Tag: 1.31.0-rc.0~13867 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=c9a3ecef59c10403e045d828392838262823db03;p=lhc%2Fweb%2Fwiklou.git Message: Correct output of wfMessage( 'non-existent-msg' )->text() The output of Message::text() should always be acceptable to pass into external html escaping, such as when the response is returned over an API request and escaped by the client side code. Calling ->text() on a non-existent key was returning the entity encoded value which leads to double encoding down the line, this patch fixes that oversight. Bug: 66199 Change-Id: Ieec94d4e4c7e5c36e5e68bbf01792e96368e54e0 --- diff --git a/includes/Message.php b/includes/Message.php index 4df0d809d6..59c51206ff 100644 --- a/includes/Message.php +++ b/includes/Message.php @@ -674,11 +674,10 @@ class Message { $string = $this->fetchMessage(); if ( $string === false ) { - $key = htmlspecialchars( $this->key ); - if ( $this->format === 'plain' ) { - return '<' . $key . '>'; + if ( $this->format === 'plain' || $this->format === 'text' ) { + return '<' . $this->key . '>'; } - return '<' . $key . '>'; + return '<' . htmlspecialchars( $this->key ) . '>'; } # Replace $* with a list of parameters for &uselang=qqx. @@ -735,10 +734,10 @@ class Message { // Doh! Cause a fatal error after all? } - if ( $this->format === 'plain' ) { + if ( $this->format === 'plain' || $this->format === 'text' ) { return '<' . $this->key . '>'; } - return '<' . $this->key . '>'; + return '<' . htmlspecialchars( $this->key ) . '>'; } } diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index f3d2a84a01..47560e613e 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -109,9 +109,15 @@ class MessageTest extends MediaWikiLangTestCase { $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) ); $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) ); $this->assertEquals( 'Main Page', wfMessage( 'mainpage' )->text() ); - $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->text() ); + $this->assertEquals( '', wfMessage( 'i-dont-exist-evar' )->text() ); + $this->assertEquals( 'exist-evar>', wfMessage( 'iexist-evar' )->text() ); $this->assertEquals( '', wfMessage( 'i-dont-exist-evar' )->plain() ); + $this->assertEquals( 'exist-evar>', wfMessage( 'iexist-evar' )->plain() ); $this->assertEquals( '<i-dont-exist-evar>', wfMessage( 'i-dont-exist-evar' )->escaped() ); + $this->assertEquals( + '<i<dont>exist-evar>', + wfMessage( 'iexist-evar' )->escaped() + ); } /**