Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/TholdStrReplaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,29 @@ public function testEveryOccurrenceIsReplaced(): void {
public function testSubjectWithoutTheTagIsUnchanged(): void {
$this->assertSame('no tags here', thold_str_replace('<X>', 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('<X>', 'value', null));
$this->assertSame('', thold_str_replace('<X>', null, null));
} finally {
restore_error_handler();
}

$this->assertSame([], $deprecations);
}
}
10 changes: 5 additions & 5 deletions thold_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading