Add exception catch.

This commit is contained in:
James Cole 2024-03-10 16:44:41 +01:00
parent 530b501fcf
commit f559ec73e0
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 20 additions and 12 deletions

View File

@ -50,12 +50,12 @@ class SecureHeaders
$csp = [ $csp = [
"default-src 'none'", "default-src 'none'",
"object-src 'none'", "object-src 'none'",
sprintf("script-src 'unsafe-eval' 'strict-dynamic' 'self' 'unsafe-inline' 'nonce-%1s' %2s", $nonce, $trackingScriptSrc), sprintf("script-src 'unsafe-eval' 'strict-dynamic' 'nonce-%1s' %2s", $nonce, $trackingScriptSrc),
"style-src 'unsafe-inline' 'self'", "style-src 'unsafe-inline' 'self'",
"base-uri 'self'", "base-uri 'self'",
"font-src 'self' data:", "font-src 'self' data:",
sprintf("connect-src 'self' %s", $trackingScriptSrc), sprintf("connect-src 'self' %s", $trackingScriptSrc),
sprintf("img-src data: 'strict-dynamic' 'self' *.tile.openstreetmap.org %s", $trackingScriptSrc), sprintf("img-src 'strict-dynamic' %s", $trackingScriptSrc),
"manifest-src 'self'", "manifest-src 'self'",
]; ];

View File

@ -31,6 +31,8 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Log;
use Symfony\Component\ExpressionLanguage\SyntaxError;
/** /**
* FireflyIII\Models\RuleAction * FireflyIII\Models\RuleAction
@ -67,25 +69,31 @@ class RuleAction extends Model
protected $casts protected $casts
= [ = [
'created_at' => 'datetime', 'created_at' => 'datetime',
'updated_at' => 'datetime', 'updated_at' => 'datetime',
'active' => 'boolean', 'active' => 'boolean',
'order' => 'int', 'order' => 'int',
'stop_processing' => 'boolean', 'stop_processing' => 'boolean',
]; ];
protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing']; protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing'];
public function getValue(array $journal): string public function getValue(array $journal): string
{ {
if (false === config('firefly.feature_flags.expression_engine')) { if (false === config('firefly.feature_flags.expression_engine')) {
\Log::debug('Expression engine is disabled, returning action value as string.'); Log::debug('Expression engine is disabled, returning action value as string.');
return (string)$this->action_value; return (string)$this->action_value;
} }
$expr = new ActionExpression($this->action_value); $expr = new ActionExpression($this->action_value);
$result = $expr->evaluate($journal);
\Log::debug(sprintf('Expression engine is enabled, result of expression "%s" is "%s".', $this->action_value, $result)); try {
$result = $expr->evaluate($journal);
} catch (SyntaxError $e) {
Log::error(sprintf('Expression engine failed to evaluate expression "%s" with error "%s".', $this->action_value, $e->getMessage()));
$result = (string)$this->action_value;
}
Log::debug(sprintf('Expression engine is enabled, result of expression "%s" is "%s".', $this->action_value, $result));
return $result; return $result;
} }