From 4c1dbc75d5256dad2de5e25174c4ddbfe544197f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 12 Sep 2013 17:27:04 +0200 Subject: [PATCH 1/4] [TwigBridge] fixed form rendering when used in a template with dynamic inheritance --- .../Bridge/Twig/Form/TwigRendererEngine.php | 4 +++- .../Tests/Extension/FormExtensionDivLayoutTest.php | 14 ++++++++++++++ .../Tests/Extension/page_dynamic_extends.html.twig | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bridge/Twig/Tests/Extension/page_dynamic_extends.html.twig diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index 05beb31565..768a0816fd 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -167,6 +167,8 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE // theme is a reference and we don't want to change it. $currentTheme = $theme; + $context = $this->environment->mergeGlobals(array()); + // The do loop takes care of template inheritance. // Add blocks from all templates in the inheritance tree, but avoid // overriding blocks already set. @@ -178,6 +180,6 @@ class TwigRendererEngine extends AbstractRendererEngine implements TwigRendererE $this->resources[$cacheKey][$block] = $blockData; } } - } while (false !== $currentTheme = $currentTheme->getParent(array())); + } while (false !== $currentTheme = $currentTheme->getParent($context)); } } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index 903db69edc..2e95db5ca6 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -64,6 +64,8 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest $environment = new \Twig_Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addGlobal('global', ''); + // the value can be any template that exists + $environment->addGlobal('dynamic_template_name', 'child_label'); $environment->addExtension($this->extension); $this->extension->initRuntime($environment); @@ -106,6 +108,18 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest ); } + public function testThemeBlockInheritanceUsingDynamicExtend() + { + $view = $this->factory + ->createNamed('name', 'email') + ->createView() + ; + + $renderer = $this->extension->renderer; + $renderer->setTheme($view, array('page_dynamic_extends.html.twig')); + $renderer->searchAndRenderBlock($view, 'row'); + } + public function isSelectedChoiceProvider() { // The commented cases should not be necessary anymore, because the diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/page_dynamic_extends.html.twig b/src/Symfony/Bridge/Twig/Tests/Extension/page_dynamic_extends.html.twig new file mode 100644 index 0000000000..ac166b7b60 --- /dev/null +++ b/src/Symfony/Bridge/Twig/Tests/Extension/page_dynamic_extends.html.twig @@ -0,0 +1 @@ +{% extends dynamic_template_name ~ '.html.twig' %} From 4f5b8f04f10b33b8e9f47a9e17aff8e4b47753d4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 12 Sep 2013 18:44:22 +0200 Subject: [PATCH 2/4] [HttpFoundation] tried to keep the original Request URI as much as possible to avoid different behavior between ::createFromGlobals() and ::create() --- src/Symfony/Component/HttpFoundation/Request.php | 13 +++++++++++-- .../Component/HttpFoundation/Tests/RequestTest.php | 4 ++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index bd16eac471..f99a091e2e 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -348,11 +348,20 @@ class Request break; } + $queryString = ''; if (isset($components['query'])) { parse_str(html_entity_decode($components['query']), $qs); - $query = array_replace($qs, $query); + + if ($query) { + $query = array_replace($qs, $query); + $queryString = http_build_query($query, '', '&'); + } else { + $query = $qs; + $queryString = $components['query']; + } + } elseif ($query) { + $queryString = http_build_query($query, '', '&'); } - $queryString = http_build_query($query, '', '&'); $server['REQUEST_URI'] = $components['path'].('' !== $queryString ? '?'.$queryString : ''); $server['QUERY_STRING'] = $queryString; diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index ce5a5ec3fc..f9868a905a 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -220,6 +220,10 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals('testnopass', $request->getUser()); $this->assertNull($request->getPassword()); $this->assertFalse($request->isSecure()); + + $request = Request::create('http://test.com/?foo'); + $this->assertEquals('/?foo', $request->getRequestUri()); + $this->assertEquals(array('foo' => ''), $request->query->all()); } /** From b591419631ec7de8db7a4b3970bfdab5b1f82d4a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 12 Sep 2013 20:46:44 +0200 Subject: [PATCH 3/4] [HttpFoundation] removed double-slashes (closes #8388) --- src/Symfony/Component/HttpFoundation/File/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 729d870cfc..c8967b1bf7 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -129,7 +129,7 @@ class File extends \SplFileInfo throw new FileException(sprintf('Unable to write in the "%s" directory', $directory)); } - $target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); + $target = trim($directory, '/\\').DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); return new File($target, false); } From 097b3763099690d127894849f5d1c12d77635bbd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 12 Sep 2013 22:07:01 +0200 Subject: [PATCH 4/4] [WebProfilerBundle] fixed toolbar for IE8 (refs #8380) --- .../Resources/views/Profiler/toolbar.html.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index d0a6a497f8..d0f4e61f28 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -1,8 +1,5 @@ {% if 'normal' != position %} - +
{% endif %}