Skip to content

Commit

Permalink
Fix for {% embed %} error line number bug
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycatalinismith authored and fabpot committed Aug 3, 2013
1 parent c35d7f2 commit 270b791
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Twig/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function updateRepr()
protected function guessTemplateInfo()
{
$template = null;
$templateClass = null;

if (version_compare(phpversion(), '5.3.6', '>=')) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
Expand All @@ -195,8 +196,11 @@ protected function guessTemplateInfo()

foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) {
$currentClass = get_class($trace['object']);
$isEmbedContainer = 0 === strpos($templateClass, $currentClass);
if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
$template = $trace['object'];
$templateClass = get_class($trace['object']);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/Twig/Tests/Fixtures/tags/embed/error_line.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
"embed" tag
--TEMPLATE(index.twig)--
FOO
{% embed "foo.twig" %}
{% block c1 %}
{{ nothing }}
{% endblock %}
{% endembed %}
BAR
--TEMPLATE(foo.twig)--
{% block c1 %}{% endblock %}
--DATA--
return array()
--EXCEPTION--
Twig_Error_Runtime: Variable "nothing" does not exist in "index.twig" at line 5

0 comments on commit 270b791

Please sign in to comment.