Test the Template regex and disable the template if it is invalid. Fixes #361

This commit is contained in:
Deon George 2025-07-07 18:11:36 +08:00
parent eeed0b04f6
commit 2ff0a10901
2 changed files with 6 additions and 2 deletions

View File

@ -38,7 +38,11 @@ class Template
// @todo Make sure we have a structural objectclass, or make the template invalid // @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)); $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->invalid = TRUE;
$this->reason = $e->getMessage(); $this->reason = $e->getMessage();
} }

View File

@ -61,7 +61,7 @@ class Entry extends Model
$to = new Template($file); $to = new Template($file);
if ($to->invalid) { 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 { } else {
$templates->put($file,new Template($file)); $templates->put($file,new Template($file));