Merge branch '1.x'

* 1.x:
  fix escaping strategy detection based on filename
  OPcache support fix
This commit is contained in:
Fabien Potencier
2015-09-01 07:51:16 +02:00
3 changed files with 17 additions and 6 deletions
+1 -1
View File
@@ -349,7 +349,7 @@ cache::
// Compile cached file into bytecode cache
if (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) {
opcache_compile_file($file);
opcache_invalidate($file);
} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
apc_compile_file($file);
}
+13 -4
View File
@@ -27,15 +27,21 @@ class Twig_FileExtensionEscapingStrategy
*
* @param string $filename The template file name
*
* @return string The escaping strategy name to use
* @return string|false The escaping strategy name to use or false to disable
*/
public static function guess($filename)
{
if (!preg_match('{\.(js|css|txt)(?:\.[^/\\\\]+)?$}', $filename, $match)) {
return 'html';
if (in_array(substr($filename, -1), array('/', '\\'))) {
return 'html'; // return html for directories
}
switch ($match[1]) {
if ('.twig' === substr($filename, -5)) {
$filename = substr($filename, 0, -5);
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
switch ($extension) {
case 'js':
return 'js';
@@ -44,6 +50,9 @@ class Twig_FileExtensionEscapingStrategy
case 'txt':
return false;
default:
return 'html';
}
}
}
@@ -16,7 +16,7 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends PHPUnit_Framework_Tes
*/
public function testGuess($strategy, $filename)
{
$this->assertEquals($strategy, Twig_FileExtensionEscapingStrategy::guess($filename));
$this->assertSame($strategy, Twig_FileExtensionEscapingStrategy::guess($filename));
}
public function getGuessData()
@@ -34,6 +34,8 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends PHPUnit_Framework_Tes
array('css', 'foo.css'),
array('css', 'foo.css.twig'),
array('css', 'foo.twig.css'),
array('css', 'foo.js.css'),
array('css', 'foo.js.css.twig'),
// js
array('js', 'foo.js'),