fix inconsistent response from twig_slice

This commit is contained in:
Rhodri Pugh
2014-09-08 19:35:00 +01:00
committed by Fabien Potencier
parent 084ca201a7
commit c740060051
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -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));
}
/**
+18
View File
@@ -130,6 +130,24 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase
{
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)