diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b7db7d..f37d225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,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: All Columns checkd on Thresholds page * issue: Special character previous value handling broken on data query indexes with special characters diff --git a/README.md b/README.md index 46310dc..4516eda 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ and become familiar with its settings. From there, you can provide overall control of thold, and set defaults for things like Email bodies, weekend exemptions, alert log retention, logging, etc. +An unset notification template field is treated as empty text. + As with much of Cacti, settings should be documented in line with the actual setting. If you find that any of these settings are ambiguous, please create a pull request with your proposed changes. diff --git a/tests/Unit/TholdStrReplaceTest.php b/tests/Unit/TholdStrReplaceTest.php index 69006c3..9e31619 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 f195d30..6ece0f7 100644 --- a/thold_functions.php +++ b/thold_functions.php @@ -8362,12 +8362,12 @@ function thold_get_cached_name(&$thold_data) { * 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) {