From cbe2ba55cefe58b5372452bca32b8ecfc9b3fe7e Mon Sep 17 00:00:00 2001 From: Fehler12 <53938045+Fehler12@users.noreply.github.com> Date: Mon, 21 Aug 2023 00:17:25 +0200 Subject: [PATCH] Added empty string check (#15235) * Added empty string check * replaced tabs with spaces replaced tabs with spaces * Removed '(', ')' and enlarged if clause * Added one space and removed an empty row * removed is_null Removed is_null check as static code analysis says that this variable cannot be null at this time * compact form * handle spaces In case the sysName is " " (one space). Good to trim anyway. --------- Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> --- app/Models/Device.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Models/Device.php b/app/Models/Device.php index 20479b5778..e640a57ef0 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -180,12 +180,15 @@ class Device extends BaseModel { $hostname_is_ip = IP::isValid($this->hostname); - return SimpleTemplate::parse($this->display ?: \LibreNMS\Config::get('device_display_default', '{{ $hostname }}'), [ + $return_value = SimpleTemplate::parse($this->display ?: \LibreNMS\Config::get('device_display_default', '{{ $hostname }}'), [ 'hostname' => $this->hostname, 'sysName' => $this->sysName ?: $this->hostname, 'sysName_fallback' => $hostname_is_ip ? $this->sysName : $this->hostname, 'ip' => $this->overwrite_ip ?: ($hostname_is_ip ? $this->hostname : $this->ip), ]); + + // in case the displayName is a string without any content, return hostname + return trim($return_value) ?: $this->hostname; } /**