From b9760efb02ec1ab086ff8b242571c675dd107acf Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 25 Aug 2015 14:59:33 +0200 Subject: [PATCH 1/2] consistently use str_replace to unify directory separators --- .../FrameworkBundle/Templating/TemplateFilenameParser.php | 2 +- .../Bundle/FrameworkBundle/Templating/TemplateNameParser.php | 2 +- .../Component/ClassLoader/Tests/ClassMapGeneratorTest.php | 4 ++-- src/Symfony/Component/Filesystem/Filesystem.php | 4 ++-- .../Finder/Iterator/ExcludeDirectoryFilterIterator.php | 2 +- src/Symfony/Component/Finder/Iterator/PathFilterIterator.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php index befb3e8f85..85825fe337 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateFilenameParser.php @@ -26,7 +26,7 @@ class TemplateFilenameParser implements TemplateNameParserInterface */ public function parse($file) { - $parts = explode('/', strtr($file, '\\', '/')); + $parts = explode('/', str_replace('\\', '/', $file)); $elements = explode('.', array_pop($parts)); if (3 > count($elements)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php index 4777fbeadb..ea347bc820 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php @@ -50,7 +50,7 @@ class TemplateNameParser extends BaseTemplateNameParser } // normalize name - $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'))); + $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', str_replace('\\', '/', $name))); if (false !== strpos($name, '..')) { throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name)); diff --git a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php index e6756f1898..7bdf5aa0dc 100644 --- a/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php +++ b/src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php @@ -140,10 +140,10 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase protected function assertEqualsNormalized($expected, $actual, $message = null) { foreach ($expected as $ns => $path) { - $expected[$ns] = strtr($path, '\\', '/'); + $expected[$ns] = str_replace('\\', '/', $path); } foreach ($actual as $ns => $path) { - $actual[$ns] = strtr($path, '\\', '/'); + $actual[$ns] = str_replace('\\', '/', $path); } $this->assertEquals($expected, $actual, $message); } diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index eea41dad66..636942a693 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -313,8 +313,8 @@ class Filesystem { // Normalize separators on Windows if ('\\' === DIRECTORY_SEPARATOR) { - $endPath = strtr($endPath, '\\', '/'); - $startPath = strtr($startPath, '\\', '/'); + $endPath = str_replace('\\', '/', $endPath); + $startPath = str_replace('\\', '/', $startPath); } // Split the paths into arrays diff --git a/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php b/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php index 4ab44d156c..66f8149446 100644 --- a/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php @@ -44,7 +44,7 @@ class ExcludeDirectoryFilterIterator extends FilterIterator public function accept() { $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath(); - $path = strtr($path, '\\', '/'); + $path = str_replace('\\', '/', $path); foreach ($this->patterns as $pattern) { if (preg_match($pattern, $path)) { return false; diff --git a/src/Symfony/Component/Finder/Iterator/PathFilterIterator.php b/src/Symfony/Component/Finder/Iterator/PathFilterIterator.php index 2bb8ebd223..4971692c69 100644 --- a/src/Symfony/Component/Finder/Iterator/PathFilterIterator.php +++ b/src/Symfony/Component/Finder/Iterator/PathFilterIterator.php @@ -29,7 +29,7 @@ class PathFilterIterator extends MultiplePcreFilterIterator $filename = $this->current()->getRelativePathname(); if ('\\' === DIRECTORY_SEPARATOR) { - $filename = strtr($filename, '\\', '/'); + $filename = str_replace('\\', '/', $filename); } // should at least not match one rule to exclude From ea92610a856ee023f15f0822c664336fa71e0b3d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 2 Aug 2015 01:30:03 +0200 Subject: [PATCH 2/2] Fix the validation of form resources to register the default theme --- .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 13 ++++++++ .../DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 30 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 08bcc1c19d..5126d27afa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -260,7 +260,7 @@ class Configuration implements ConfigurationInterface ->addDefaultChildrenIfNoneSet() ->prototype('scalar')->defaultValue('FrameworkBundle:Form')->end() ->validate() - ->ifNotInArray(array('FrameworkBundle:Form')) + ->ifTrue(function ($v) {return !in_array('FrameworkBundle:Form', $v); }) ->then(function ($v) { return array_merge(array('FrameworkBundle:Form'), $v); }) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 319e643d29..fba0fb2ab3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -27,6 +27,19 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase ); } + public function testDoNoDuplicateDefaultFormResources() + { + $input = array('templating' => array( + 'form' => array('resources' => array('FrameworkBundle:Form')), + 'engines' => array('php'), + )); + + $processor = new Processor(); + $config = $processor->processConfiguration(new Configuration(), array($input)); + + $this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']); + } + /** * @dataProvider getTestValidTrustedProxiesData */ diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 30c6f6ffab..f4d3dd5ac9 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -58,7 +58,7 @@ class Configuration implements ConfigurationInterface ->prototype('scalar')->defaultValue('form_div_layout.html.twig')->end() ->example(array('MyBundle::form.html.twig')) ->validate() - ->ifNotInArray(array('form_div_layout.html.twig')) + ->ifTrue(function ($v) {return !in_array('form_div_layout.html.twig', $v); }) ->then(function ($v) { return array_merge(array('form_div_layout.html.twig'), $v); }) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000000..7160345fd3 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; + +use Symfony\Bundle\TwigBundle\DependencyInjection\Configuration; +use Symfony\Component\Config\Definition\Processor; + +class ConfigurationTest extends \PHPUnit_Framework_TestCase +{ + public function testDoNoDuplicateDefaultFormResources() + { + $input = array( + 'form' => array('resources' => array('form_div_layout.html.twig')), + ); + + $processor = new Processor(); + $config = $processor->processConfiguration(new Configuration(), array($input)); + + $this->assertEquals(array('form_div_layout.html.twig'), $config['form']['resources']); + } +}