diff --git a/ext/twig/twig.c b/ext/twig/twig.c index 1fea683a4..f871d1eba 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -1030,7 +1030,7 @@ PHP_FUNCTION(twig_template_get_attributes) // ret can be null, if e.g. the called method throws an exception if (ret) { if (TWIG_INSTANCE_OF_USERLAND(object, "Twig_TemplateInterface" TSRMLS_CC)) { - if (Z_STRVAL_P(ret) == "") { + if (Z_STRLEN_P(ret) == 0) { free_ret = 1; } else { zval *charset = TWIG_CALL_USER_FUNC_ARRAY(TWIG_PROPERTY_CHAR(template, "env" TSRMLS_CC), "getCharset", NULL TSRMLS_CC); diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 40096076d..448bdf895 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -105,6 +105,40 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase return $tests; } + /** + * @dataProvider getGetAttributeWithTemplateAsObject + */ + public function testGetAttributeWithTemplateAsObject($useExt) + { + $template = new Twig_TemplateTest(new Twig_Environment(), $useExt); + $template1 = new Twig_TemplateTest(new Twig_Environment(), false); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'string')); + $this->assertEquals('some_string', $template->getAttribute($template1, 'string')); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'true')); + $this->assertEquals('1', $template->getAttribute($template1, 'true')); + + $this->assertInstanceof('Twig_Markup', $template->getAttribute($template1, 'zero')); + $this->assertEquals('0', $template->getAttribute($template1, 'zero')); + + $this->assertNotInstanceof('Twig_Markup', $template->getAttribute($template1, 'empty')); + $this->assertSame('', $template->getAttribute($template1, 'empty')); + } + + public function getGetAttributeWithTemplateAsObject() + { + $bools = array( + array(false), + ); + + if (function_exists('twig_template_get_attributes')) { + $bools[] = array(true); + } + + return $bools; + } + /** * @dataProvider getGetAttributeTests */ @@ -289,6 +323,26 @@ class Twig_TemplateTest extends Twig_Template Twig_Template::clearCache(); } + public function getZero() + { + return 0; + } + + public function getEmpty() + { + return ''; + } + + public function getString() + { + return 'some_string'; + } + + public function getTrue() + { + return true; + } + public function getTemplateName() { }