From 7a1d6dbdbb9220a22305f7fd802e1f595104e0ce Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Thu, 8 Oct 2020 18:54:36 +0200 Subject: [PATCH] Avoid array_filter on explode() The array_filter is likely meant to empty the array if the empty string was exploded ( `explode( "\n", '' ) === [ '' ]` ). However, it can also remove other stuff, e.g. the string '0'. An explicit comparison is easier to read & interpret, marginally faster, and avoids rare but not impossible edge cases. Change-Id: Ie77d65b56319664a2ac370f32341dc72b619a635 --- includes/AbuseFilterHooks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/AbuseFilterHooks.php b/includes/AbuseFilterHooks.php index 6f95fb2fc..d2acc7e09 100644 --- a/includes/AbuseFilterHooks.php +++ b/includes/AbuseFilterHooks.php @@ -412,7 +412,7 @@ class AbuseFilterHooks { $tags = []; foreach ( $res as $row ) { $tags = array_merge( - array_filter( explode( "\n", $row->afa_parameters ) ), + $row->afa_parameters ? explode( "\n", $row->afa_parameters ) : [], $tags ); } @@ -430,7 +430,7 @@ class AbuseFilterHooks { foreach ( $res as $row ) { $tags = array_merge( - array_filter( explode( "\n", $row->afa_parameters ) ), + $row->afa_parameters ? explode( "\n", $row->afa_parameters ) : [], $tags ); }