PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: twigphp/Twig (php)

Issue:
[BC-Break] Twig 2.14.9 broke `filter` tag with `spaceless`
Hi,

we've upgraded our (legacy) code base with the security release Twig 2.14.11 and suddenly had an issue with totally strange rendering on some pages. I've tracked the issue down to the 2.14.9 release.

We've got some old templates using the `filter` tag with the `spaceless` filter:

~~~
{% filter spaceless %}
  something A
{% endfilter %}

{% filter spaceless %}
  something B
{% endfilter %}

{% filter spaceless %}
  something C
{% endfilter %}
~~~

Quote simpliefied but basically multiple tags in a bunch of blocks and template inheritance. The result is that all tags render the content of the **first** tag:

~~~
something A
something A
something A
~~~

I've checked the commits and found nothing obvious which could result in such a strange behaviour. 😕 

Cheers
Matthias

Pull request:
do not reuse internally generated variable names during parsing
fixes #3647 

Patch:
diff --git a/src/Parser.php b/src/Parser.php
index eb2ee15c..0ef3dc2a 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -62,7 +62,7 @@ class Parser
     public function parse(TokenStream $stream, $test = null, $dropNeedle = false)
     {
         $vars = get_object_vars($this);
-        unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames']);
+        unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser'], $vars['reservedMacroNames'], $vars['varNameSalt']);
         $this->stack[] = $vars;
 
         // tag handlers
@@ -92,7 +92,6 @@ class Parser
         $this->blockStack = [];
         $this->importedSymbols = [[]];
         $this->embeddedTemplates = [];
-        $this->varNameSalt = 0;
 
         try {
             $body = $this->subparse($test, $dropNeedle);


Test patch:
diff --git a/tests/Fixtures/tags/filter/spaceless_parent.legacy.test b/tests/Fixtures/tags/filter/spaceless_parent.legacy.test
new file mode 100644
index 00000000..5715566b
--- /dev/null
+++ b/tests/Fixtures/tags/filter/spaceless_parent.legacy.test
@@ -0,0 +1,33 @@
+--TEST--
+blocks and autoescape
+--DEPRECATION--
+The "filter" tag in "index.twig" at line 8 is deprecated since Twig 2.9, use the "apply" tag instead.
+--TEMPLATE--
+{% extends 'parent.twig' %}
+
+{% block foo %}
+  {{ parent() }}
+
+  Foo child:
+  {% filter spaceless %}
+    something B
+  {% endfilter %}
+
+{% endblock %}
+--TEMPLATE(parent.twig)--
+{% block foo %}
+  Foo Parent:
+  {% filter spaceless %}
+    something A
+  {% endfilter %}
+
+{% endblock %}
+--DATA--
+return []
+--EXPECT--
+    Foo Parent:
+  something A
+
+
+  Foo child:
+  something B