From 2ff0a10901aa1de8eb6db14094bbb64b9df0d473 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 7 Jul 2025 18:11:36 +0800 Subject: [PATCH] Test the Template regex and disable the template if it is invalid. Fixes #361 --- app/Classes/Template.php | 6 +++++- app/Ldap/Entry.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Classes/Template.php b/app/Classes/Template.php index d01458e5..8798bb7f 100644 --- a/app/Classes/Template.php +++ b/app/Classes/Template.php @@ -38,7 +38,11 @@ class Template // @todo Make sure we have a structural objectclass, or make the template invalid $this->template = collect(json_decode($td->get($file),null,512,JSON_OBJECT_AS_ARRAY|JSON_THROW_ON_ERROR)); - } catch (\JsonException $e) { + // Also test the regex is valid. + if ($this->template->has('regexp')) + preg_match($this->regexp,''); + + } catch (\ErrorException|\JsonException $e) { $this->invalid = TRUE; $this->reason = $e->getMessage(); } diff --git a/app/Ldap/Entry.php b/app/Ldap/Entry.php index 084b4f1e..22ab025a 100644 --- a/app/Ldap/Entry.php +++ b/app/Ldap/Entry.php @@ -61,7 +61,7 @@ class Entry extends Model $to = new Template($file); if ($to->invalid) { - Log::debug(sprintf('Template [%s] is not valid (%s) - ignoring',$file,$to->reason)); + Log::alert(sprintf('Template [%s] is not valid (%s) - ignoring',$file,$to->reason)); } else { $templates->put($file,new Template($file));