diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eaa3ff6..1aeb9837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ * issue#710: Fixing Typo in thold_daemons.service File * issue#714: Increase the Name column to 255 characters * issue#719: Plugin Disabled due to mix of string and int +* issue#814: Normalize nullable notification template text before replacement * issue#784: Retry failed queued email notifications with bounded exponential backoff * issue#812: Recover stale notification claims, scope worker drains, and deprecate the ignored notification --thread option * issue: All Columns checkd on Thresholds page diff --git a/tests/Unit/TholdStrReplaceTest.php b/tests/Unit/TholdStrReplaceTest.php index 69006c39..9e31619c 100644 --- a/tests/Unit/TholdStrReplaceTest.php +++ b/tests/Unit/TholdStrReplaceTest.php @@ -91,4 +91,29 @@ public function testEveryOccurrenceIsReplaced(): void { public function testSubjectWithoutTheTagIsUnchanged(): void { $this->assertSame('no tags here', thold_str_replace('', 5, 'no tags here')); } + + /** + * @return void + */ + public function testNullableSubjectIsNormalizedAtTheBoundary(): void { + $deprecations = []; + set_error_handler(static function ($severity, $message) use (&$deprecations) { + if ($severity === E_DEPRECATED) { + $deprecations[] = $message; + + return true; + } + + return false; + }); + + try { + $this->assertSame('', thold_str_replace('', 'value', null)); + $this->assertSame('', thold_str_replace('', null, null)); + } finally { + restore_error_handler(); + } + + $this->assertSame([], $deprecations); + } } diff --git a/thold_functions.php b/thold_functions.php index e42954b0..37f19fa3 100644 --- a/thold_functions.php +++ b/thold_functions.php @@ -9221,12 +9221,12 @@ function thold_rlike_clause($value) { * blanking it produced alert bodies reading "Current value is " for exactly * the case an operator most needs to see. * - * @param string $search Tag to replace. - * @param mixed $replace Value to substitute. - * @param string $subject Text containing the tag. + * @param string $search Tag to replace. + * @param mixed $replace Value to substitute. + * @param string|null $subject Text containing the tag. */ -function thold_str_replace(string $search, $replace, string $subject): string { - return str_replace($search, $replace ?? '', $subject); +function thold_str_replace(string $search, $replace, ?string $subject): string { + return str_replace($search, $replace ?? '', $subject ?? ''); } function thold_template_import($xml_data) {