Skip to content

Commit

Permalink
Fix custom escaper null values
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf authored and fabpot committed Sep 30, 2015
1 parent 79249fc commit 6f84981
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* 1.22.3 (2015-XX-XX)

* changed template cache names to take into account the Twig C extension

* 1.22.2 (2015-09-22)

* fixed a race condition in template loading
Expand Down
2 changes: 1 addition & 1 deletion ext/twig/php_twig.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef PHP_TWIG_H
#define PHP_TWIG_H

#define PHP_TWIG_VERSION "1.22.2"
#define PHP_TWIG_VERSION "1.22.3-DEV"

#include "php.h"

Expand Down
12 changes: 11 additions & 1 deletion lib/Twig/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class Twig_Environment
{
const VERSION = '1.22.2';
const VERSION = '1.22.3-DEV';

protected $charset;
protected $loader;
Expand Down Expand Up @@ -291,6 +291,12 @@ public function getCacheFilename($name)
/**
* Gets the template class associated with the given string.
*
* The generated template class is based on the following parameters:
*
* * The cache key for the given template;
* * The currently enabled extensions;
* * Whether the Twig C extension is available or not.
*
* @param string $name The name for which to calculate the template class name
* @param int $index The index if it is an embedded template
*
Expand All @@ -300,6 +306,10 @@ public function getTemplateClass($name, $index = null)
{
$key = $this->getLoader()->getCacheKey($name).'__'.implode('__', array_keys($this->extensions));

if (function_exists('twig_template_get_attributes')) {
$key .= '__cext';
}

return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '_'.$index);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Twig/Extension/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
if (!is_string($string)) {
if (is_object($string) && method_exists($string, '__toString')) {
$string = (string) $string;
} else {
} elseif (in_array($strategy, array('html', 'js', 'css', 'html_attr', 'url'))) {
return $string;
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/Twig/Tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function testCustomEscaper()
$twig->getExtension('core')->setEscaper('foo', 'foo_escaper_for_test');

$this->assertEquals('fooUTF-8', twig_escape_filter($twig, 'foo', 'foo'));
$this->assertEquals('UTF-8', twig_escape_filter($twig, null, 'foo'));
$this->assertEquals('42UTF-8', twig_escape_filter($twig, 42, 'foo'));
}

/**
Expand Down

0 comments on commit 6f84981

Please sign in to comment.