aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-03 00:21:50 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-05-03 00:21:50 +0200
commita995f1166c7c58ef2ae1f3474c4c1674110fab5e (patch)
tree016054bc073c188924457ab098e9b61bf54bc264
parent1399d60954b484ac5ee0c9aca09b9a6221c04de0 (diff)
parentc5660ed177d05cd1139546833b2888115ec15ce8 (diff)
downloadforums-a995f1166c7c58ef2ae1f3474c4c1674110fab5e.tar
forums-a995f1166c7c58ef2ae1f3474c4c1674110fab5e.tar.gz
forums-a995f1166c7c58ef2ae1f3474c4c1674110fab5e.tar.bz2
forums-a995f1166c7c58ef2ae1f3474c4c1674110fab5e.tar.xz
forums-a995f1166c7c58ef2ae1f3474c4c1674110fab5e.zip
Merge pull request #2391 from naderman/ticket/12382
[ticket/12382] Allow nested loops in included files.
-rw-r--r--phpBB/phpbb/template/twig/lexer.php15
-rw-r--r--tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html4
-rw-r--r--tests/template/template_events_test.php1
-rw-r--r--tests/template/template_test.php1
-rw-r--r--tests/template/templates/loop_nested_include1.html4
5 files changed, 15 insertions, 10 deletions
diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php
index f4efc58540..49577f6e95 100644
--- a/phpBB/phpbb/template/twig/lexer.php
+++ b/phpBB/phpbb/template/twig/lexer.php
@@ -191,9 +191,16 @@ class lexer extends \Twig_Lexer
$parent_class = $this;
$callback = function ($matches) use ($parent_class, $parent_nodes)
{
- $name = $matches[1];
- $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis
- $body = $matches[3];
+ $hard_parents = explode('.', $matches[1]);
+ array_pop($hard_parents); // ends with .
+ if ($hard_parents)
+ {
+ $parent_nodes = array_merge($hard_parents, $parent_nodes);
+ }
+
+ $name = $matches[2];
+ $subset = trim(substr($matches[3], 1, -1)); // Remove parenthesis
+ $body = $matches[4];
// Replace <!-- BEGINELSE -->
$body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body);
@@ -242,7 +249,7 @@ class lexer extends \Twig_Lexer
return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}";
};
- return preg_replace_callback('#<!-- BEGIN ([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1 -->#s', $callback, $code);
+ return preg_replace_callback('#<!-- BEGIN ((?:[a-zA-Z0-9_]+\.)*)([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1\2 -->#s', $callback, $code);
}
/**
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
index 4fdba859f3..98fa1770ba 100644
--- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
+++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event/test_event_subloop.html
@@ -1,2 +1,2 @@
-[{event_loop.S_ROW_COUNT}<!-- BEGIN subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
-<!-- END subloop -->]
+[{event_loop.S_ROW_COUNT}<!-- BEGIN event_loop.subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
+<!-- END event_loop.subloop -->]
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index d09f22944f..866d42d831 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -102,7 +102,6 @@ Zeta test event in all',
),
array(),
'event_loop[0[subloop:0]]',
- 'Event files are missing opened parent loops: PHPBB3-12382',
),
);
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index 49804c26c5..0d19e7afd1 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -330,7 +330,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
"[bar|[bar|]][bar1|[bar1|[bar1|works]]]",
array(),
- 'Included files are missing opened parent loops: PHPBB3-12382',
),
/* Does not pass with the current implementation.
array(
diff --git a/tests/template/templates/loop_nested_include1.html b/tests/template/templates/loop_nested_include1.html
index 0f1a180b4d..88efffc99c 100644
--- a/tests/template/templates/loop_nested_include1.html
+++ b/tests/template/templates/loop_nested_include1.html
@@ -1,5 +1,5 @@
[{test_loop.foo}|
-<!-- BEGIN inner -->
+<!-- BEGIN test_loop.inner -->
[{test_loop.foo}|
{test_loop.inner.myinner}]
-<!-- END inner -->]
+<!-- END test_loop.inner -->]