diff --git a/CHANGELOG b/CHANGELOG index a29d4019e..ee6f4d87a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ # 3.12.0 (2024-XX-XX) + * Deprecate the `spaceless` filter * Deprecate some internal methods from `Parser`: `getBlockStack()`, `hasBlock()`, `getBlock()`, `hasMacro()`, `hasTraits()`, `getParent()` * Deprecate passing `null` to `Twig\Parser::setParent()` * Update `Node::__toString()` to include the node tag if set diff --git a/doc/deprecated.rst b/doc/deprecated.rst index 83a33a537..950d961dd 100644 --- a/doc/deprecated.rst +++ b/doc/deprecated.rst @@ -180,3 +180,9 @@ Templates in ``Environment::resolveTemplate()``, ``Environment::load()``, and ``Template::loadTemplate()``); pass instances of ``Twig\TemplateWrapper`` instead. + +Filters +------- + +* The ``spaceless`` filter is deprecated as of Twig 3.12 and will be removed in + Twig 4.0. diff --git a/doc/filters/spaceless.rst b/doc/filters/spaceless.rst index 9a213c370..7a8e4093e 100644 --- a/doc/filters/spaceless.rst +++ b/doc/filters/spaceless.rst @@ -1,6 +1,10 @@ ``spaceless`` ============= +.. warning:: + + The ``spaceless`` filter is deprecated as of Twig 3.12. + Use the ``spaceless`` filter to remove whitespace *between HTML tags*, not whitespace within HTML tags or whitespace in plain text: diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index cd2f5d7e6..14dde136a 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -215,7 +215,7 @@ final class CoreExtension extends AbstractExtension new TwigFilter('striptags', [self::class, 'striptags']), new TwigFilter('trim', [self::class, 'trim']), new TwigFilter('nl2br', [self::class, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]), - new TwigFilter('spaceless', [self::class, 'spaceless'], ['is_safe' => ['html']]), + new TwigFilter('spaceless', [self::class, 'spaceless'], ['is_safe' => ['html'], 'deprecated' => '3.12', 'deprecating_package' => 'twig/twig']), // array helpers new TwigFilter('join', [self::class, 'join']), diff --git a/tests/Fixtures/filters/spaceless.legacy.test b/tests/Fixtures/filters/spaceless.legacy.test new file mode 100644 index 000000000..6a01241e7 --- /dev/null +++ b/tests/Fixtures/filters/spaceless.legacy.test @@ -0,0 +1,16 @@ +--TEST-- +"spaceless" filter +--DEPRECATION-- +Since twig/twig 3.12: Twig Filter "spaceless" is deprecated in index.twig at line 2. +Since twig/twig 3.12: Twig Filter "spaceless" is deprecated in index.twig at line 3. +Since twig/twig 3.12: Twig Filter "spaceless" is deprecated in index.twig at line 4. +--TEMPLATE-- +{{ "
foo
"|spaceless }} +*{{ ""|spaceless }}* +*{{ null|spaceless }}* +--DATA-- +return [] +--EXPECT-- +
foo
+** +** diff --git a/tests/Fixtures/filters/spaceless.test b/tests/Fixtures/filters/spaceless.test deleted file mode 100644 index 166a7ea0b..000000000 --- a/tests/Fixtures/filters/spaceless.test +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -"spaceless" filter ---TEMPLATE-- -{{ "
foo
"|spaceless }} -*{{ ""|spaceless }}* -*{{ null|spaceless }}* ---DATA-- -return [] ---EXPECT-- -
foo
-** -** diff --git a/tests/Fixtures/macros/macro_with_capture.test b/tests/Fixtures/macros/macro_with_capture.test index f67a7fcdb..2f9caed6e 100644 --- a/tests/Fixtures/macros/macro_with_capture.test +++ b/tests/Fixtures/macros/macro_with_capture.test @@ -4,11 +4,11 @@ macro {{ _self.some_macro() }} {% macro some_macro() %} - {% apply spaceless %} + {% apply upper %} {% if true %}foo{% endif %} {% endapply %} {% endmacro %} --DATA-- return [] --EXPECT-- -foo +FOO diff --git a/tests/Fixtures/tags/apply/scope.test b/tests/Fixtures/tags/apply/scope.test index a87ff9116..ff8a23116 100644 --- a/tests/Fixtures/tags/apply/scope.test +++ b/tests/Fixtures/tags/apply/scope.test @@ -2,7 +2,7 @@ "apply" tag does not create a new scope --TEMPLATE-- {% set foo = 'baz' %} -{% apply spaceless %} +{% apply upper %} {% set foo = 'foo' %} {% set bar = 'bar' %} {% endapply %}