mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
fix inconsistent response from twig_slice
This commit is contained in:
committed by
Fabien Potencier
parent
084ca201a7
commit
c740060051
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user