Sanitizer::normalizeWhitespace warn on preg_replace error

Log a warning with preg_replace error instead of passing null to trim.

Bug: T385519
Change-Id: If4ad78168d7899685f4fa1f1d89245c85f0beb0b
(cherry picked from commit 270499b6e1f96f402c852843d446a7946589986b)
This commit is contained in:
David Causse 2025-03-05 15:26:46 +01:00 committed by Reedy
parent 0da8f5d929
commit 332d1dfd83

View file

@ -1136,10 +1136,12 @@ class Sanitizer {
}
private static function normalizeWhitespace( string $text ): string {
return trim( preg_replace(
'/(?:\r\n|[\x20\x0d\x0a\x09])+/',
' ',
$text ) );
$normalized = preg_replace( '/(?:\r\n|[\x20\x0d\x0a\x09])+/', ' ', $text );
if ( $normalized === null ) {
wfLogWarning( __METHOD__ . ': Failed to normalize whitespace: ' . preg_last_error() );
return "";
}
return trim( $normalized );
}
/**