Skip to content

Commit

Permalink
fix inconsistent response from twig_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
rodnaph authored and fabpot committed Sep 30, 2014
1 parent 084ca20 commit c740060
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Core.php
Expand Up @@ -705,7 +705,7 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese
return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset);
}

return null === $length ? substr($item, $start) : substr($item, $start, $length);
return (string) (null === $length ? substr($item, $start) : substr($item, $start, $length));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/Twig/Tests/Extension/CoreTest.php
Expand Up @@ -130,6 +130,24 @@ public function testUnknownCustomEscaper()
{
twig_escape_filter(new Twig_Environment(), 'foo', 'bar');
}

public function testTwigFirst()
{
$twig = new Twig_Environment();
$this->assertEquals('a', twig_first($twig, 'abc'));
$this->assertEquals(1, twig_first($twig, array(1, 2, 3)));
$this->assertEquals('', twig_first($twig, null));
$this->assertEquals('', twig_first($twig, ''));
}

public function testTwigLast()
{
$twig = new Twig_Environment();
$this->assertEquals('c', twig_last($twig, 'abc'));
$this->assertEquals(3, twig_last($twig, array(1, 2, 3)));
$this->assertEquals('', twig_last($twig, null));
$this->assertEquals('', twig_last($twig, ''));
}
}

function foo_escaper_for_test(Twig_Environment $env, $string, $charset)
Expand Down

0 comments on commit c740060

Please sign in to comment.