From 40ceba267ab2985d1a174f97ec985bf8cc687534 Mon Sep 17 00:00:00 2001 From: Benjamin Nussbaum Date: Tue, 2 Sep 2025 14:33:54 +0200 Subject: [PATCH] feat: allow to url_encode array in polling url --- app/Liquid/Filters/StandardFilters.php | 20 +++++++++++++ app/Models/Plugin.php | 2 ++ ...terTest.php => PluginLiquidFilterTest.php} | 30 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 app/Liquid/Filters/StandardFilters.php rename tests/Feature/{PluginLiquidWhereFilterTest.php => PluginLiquidFilterTest.php} (76%) diff --git a/app/Liquid/Filters/StandardFilters.php b/app/Liquid/Filters/StandardFilters.php new file mode 100644 index 0000000..4db86a0 --- /dev/null +++ b/app/Liquid/Filters/StandardFilters.php @@ -0,0 +1,20 @@ +filterRegistry->register(StandardFilters::class); $liquidTemplate = $environment->parseString($template); $context = $environment->newRenderContext(data: $variables); diff --git a/tests/Feature/PluginLiquidWhereFilterTest.php b/tests/Feature/PluginLiquidFilterTest.php similarity index 76% rename from tests/Feature/PluginLiquidWhereFilterTest.php rename to tests/Feature/PluginLiquidFilterTest.php index c165109..fb429ae 100644 --- a/tests/Feature/PluginLiquidWhereFilterTest.php +++ b/tests/Feature/PluginLiquidFilterTest.php @@ -2,7 +2,9 @@ declare(strict_types=1); +use App\Liquid\Filters\StandardFilters; use App\Models\Plugin; +use Keepsuit\Liquid\Environment; /** * Tests for the Liquid where filter functionality @@ -92,3 +94,31 @@ LIQUID // Should not contain the low tide data $this->assertStringNotContainsString('"type":"L"', $result); }); + +it('encodes arrays for url_encode as JSON with spaces after commas and then percent-encodes', function () { + /** @var Environment $env */ + $env = app('liquid.environment'); + $env->filterRegistry->register(StandardFilters::class); + + $template = $env->parseString('{{ categories | url_encode }}'); + + $output = $template->render($env->newRenderContext([ + 'categories' => ['common', 'obscure'], + ])); + + expect($output)->toBe('%5B%22common%22%2C%22obscure%22%5D'); +}); + +it('keeps scalar url_encode behavior intact', function () { + /** @var Environment $env */ + $env = app('liquid.environment'); + $env->filterRegistry->register(StandardFilters::class); + + $template = $env->parseString('{{ text | url_encode }}'); + + $output = $template->render($env->newRenderContext([ + 'text' => 'hello world', + ])); + + expect($output)->toBe('hello+world'); +});