Improve string handling around trim()

trim() would always return a string, even with null as input
Keep the strval to make visible that this gets unsafe input

Change-Id: I6ff0ce307f6a8ac21669d6db693e5ff27767a55d
This commit is contained in:
Umherirrender 2021-09-02 21:29:25 +02:00
parent dfee99db2e
commit a892ae21f7
2 changed files with 6 additions and 8 deletions

View file

@ -782,9 +782,9 @@ class CategoryTree {
* @return null|Title
*/
public static function makeTitle( $title ) {
$title = trim( $title );
$title = trim( strval( $title ) );
if ( strval( $title ) === '' ) {
if ( $title === '' ) {
return null;
}

View file

@ -76,10 +76,10 @@ class CategoryTreePage extends SpecialPage {
$this->addHelpLink( 'Extension:CategoryTree' );
$request = $this->getRequest();
if ( $par ) {
$this->target = $par;
$this->target = trim( $par );
} else {
$this->target = $request->getVal( 'target' );
if ( $this->target === null ) {
$this->target = trim( $request->getVal( 'target', '' ) );
if ( $this->target !== '' ) {
$rootcategory = $this->msg( 'rootcategory' );
if ( $rootcategory->exists() ) {
$this->target = $rootcategory->text();
@ -87,8 +87,6 @@ class CategoryTreePage extends SpecialPage {
}
}
$this->target = trim( $this->target );
$options = [];
$config = $this->getConfig();
@ -110,7 +108,7 @@ class CategoryTreePage extends SpecialPage {
$this->executeInputForm();
if ( $this->target !== '' && $this->target !== null ) {
if ( $this->target !== '' ) {
CategoryTree::setHeaders( $output );
$title = CategoryTree::makeTitle( $this->target );