Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
Guard expression resolver against malformed-UTF-8 json_encode
Paulo Castellano1b2ff23dff27
diff --git a/app/Services/Automation/ExpressionResolver.php b/app/Services/Automation/ExpressionResolver.phpindex 492ed53d1..f86b15577 100644--- a/app/Services/Automation/ExpressionResolver.php+++ b/app/Services/Automation/ExpressionResolver.php@@ -58,6 +58,8 @@ class ExpressionResolverreturn (string) $value;}- return json_encode($value);+ // json_encode returns false on malformed UTF-8 (plausible for scraped+ // feed/HTTP payloads); the method must still return a string.+ return json_encode($value, JSON_PARTIAL_OUTPUT_ON_ERROR) ?: '';}}diff --git a/tests/Unit/Automation/ExpressionResolverTest.php b/tests/Unit/Automation/ExpressionResolverTest.phpindex cbdb2f4aa..bed7c6b6f 100644--- a/tests/Unit/Automation/ExpressionResolverTest.php+++ b/tests/Unit/Automation/ExpressionResolverTest.php@@ -50,3 +50,17 @@ it('handles non-string values by casting', function () {it('passes through templates with no variables', function () {expect($this->resolver->resolve('plain text', []))->toBe('plain text');});++it('json-encodes array values', function () {+ $context = ['fetched' => ['tags' => ['a', 'b']]];++ expect($this->resolver->resolve('{{ fetched.tags }}', $context))->toBe('["a","b"]');+});++it('does not throw when an array value contains malformed UTF-8', function () {+ // Scraped feed/HTTP payloads can carry invalid UTF-8; json_encode returns+ // false for it, but the resolver must still yield a string.+ $context = ['fetched' => ['body' => ["bad\xB1utf8"]]];++ expect($this->resolver->resolve('{{ fetched.body }}', $context))->toBeString();+});