From 3c0b9c5b202d9d75695c5fb92425fadb07324763 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 22 Jan 2012 10:12:26 +0100 Subject: [PATCH 01/11] [DoctrineBridge] enhanced an error message (closes #3155) --- .../Form/ChoiceList/EntityChoiceList.php | 2 +- .../Form/ChoiceList/EntityChoiceListTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 6a6eb0fd3d..a2b61b0ca7 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -185,7 +185,7 @@ class EntityChoiceList extends ArrayChoiceList } else { // Otherwise expect a __toString() method in the entity if (!method_exists($entity, '__toString')) { - throw new FormException('Entities passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).'); + throw new FormException(sprintf('Entity "%s" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).', $this->class)); } $value = (string) $entity; diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index 04ecbe4660..c263c124cd 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -40,6 +40,33 @@ class EntityChoiceListTest extends DoctrineOrmTestCase $this->em = null; } + /** + * @expectedException Symfony\Component\Form\Exception\FormException + * @expectedMessage Entity "Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option). + */ + public function testEntitesMustHaveAToStringMethod() + { + $entity1 = new SingleIdentEntity(1, 'Foo'); + $entity2 = new SingleIdentEntity(2, 'Bar'); + + // Persist for managed state + $this->em->persist($entity1); + $this->em->persist($entity2); + + $choiceList = new EntityChoiceList( + $this->em, + self::SINGLE_IDENT_CLASS, + null, + null, + array( + $entity1, + $entity2, + ) + ); + + $choiceList->getEntities(); + } + /** * @expectedException Symfony\Component\Form\Exception\FormException */ From 7c338de4127561553b295bceefd82377c9f8a1ac Mon Sep 17 00:00:00 2001 From: Gerard van Helden Date: Sat, 21 Jan 2012 00:01:42 +0100 Subject: [PATCH 02/11] changed docs as proposed in #3110 --- src/Symfony/Component/Config/Definition/VariableNode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/VariableNode.php b/src/Symfony/Component/Config/Definition/VariableNode.php index 87d2f9662d..69dfea6d87 100644 --- a/src/Symfony/Component/Config/Definition/VariableNode.php +++ b/src/Symfony/Component/Config/Definition/VariableNode.php @@ -14,9 +14,9 @@ namespace Symfony\Component\Config\Definition; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; /** - * This node represents a variable value in the config tree. + * This node represents a value of variable type in the config tree. * - * This node is intended for arbitrary variables. + * This node is intended for values of arbitrary type. * Any PHP type is accepted as a value. * * @author Jeremy Mikola From 7f96c8ad176705b5a58503b301d8088c34f6c176 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 24 Jan 2012 19:27:21 +0100 Subject: [PATCH 03/11] [HttpKernel] Prevent php script execution in cached ESI pages using HttpCache --- src/Symfony/Component/HttpKernel/HttpCache/Esi.php | 1 + .../Tests/Component/HttpKernel/HttpCache/EsiTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php index 2c48163c17..74c01fe4df 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Esi.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php @@ -154,6 +154,7 @@ class Esi // we don't use a proper XML parser here as we can have ESI tags in a plain text response $content = $response->getContent(); + $content = str_replace(array('', ''), $content); $content = preg_replace_callback('##', array($this, 'handleEsiIncludeTag'), $content); $content = preg_replace('#]*/>#', '', $content); $content = preg_replace('#.*?#', '', $content); diff --git a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php index 74e5f0d27b..bceb7cc1d6 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php @@ -109,6 +109,17 @@ class EsiTest extends \PHPUnit_Framework_TestCase $this->assertEquals('foo esi->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent()); } + public function testProcessEscapesPhpTags() + { + $esi = new Esi(); + + $request = Request::create('/'); + $response = new Response('foo <%= "lala" %>'); + $esi->process($request, $response); + + $this->assertEquals('foo php die("foo"); ?>= "lala" %>', $response->getContent()); + } + /** * @expectedException RuntimeException */ From e814d273c2163e4d0c3453e8cbd18577e684288f Mon Sep 17 00:00:00 2001 From: Manuel Kiessling Date: Tue, 17 Jan 2012 18:33:18 +0100 Subject: [PATCH 04/11] [FormType] Fixed broken MoneyType regexp for JPY The regexp in MoneyType doesn't work if currency format has no decimal (like JPY) and doesn't work either if the currency symbol is unicode This change fixes both issues and adds a unit test --- .../Component/Form/Extension/Core/Type/MoneyType.php | 2 +- .../Form/Extension/Core/Type/MoneyTypeTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php index 1dc555999d..7a8bd99fd6 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php @@ -100,7 +100,7 @@ class MoneyType extends AbstractType // the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8) - preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches); + preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches); if (!empty($matches[1])) { self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}'; diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php index 8563cfd6b4..d5fdd1bda6 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php @@ -11,7 +11,10 @@ namespace Symfony\Tests\Component\Form\Extension\Core\Type; +use Symfony\Component\Form\FormFactory; + require_once __DIR__ . '/LocalizedTestCase.php'; +require_once __DIR__ . '/../../../../../../../../src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php'; class MoneyTypeTest extends LocalizedTestCase { @@ -24,4 +27,13 @@ class MoneyTypeTest extends LocalizedTestCase $this->assertSame('{{ widget }} €', $view->get('money_pattern')); } + + public function testMoneyPatternWorksForYen() + { + \Locale::setDefault('en_US'); + + $form = $this->factory->create('money', null, array('currency' => 'JPY')); + $view = $form->createView(); + $this->assertTrue((bool)strstr($view->get('money_pattern'), '¥')); + } } From 6090deef9092e8008cb858b8edff3c79639e44fe Mon Sep 17 00:00:00 2001 From: Manuel Kiessling Date: Thu, 26 Jan 2012 15:40:46 +0100 Subject: [PATCH 05/11] [FormType] Adopted MoneyTypeTest::testMoneyPatternWorksForYen to CS --- .../Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php index d5fdd1bda6..cfe7c965da 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php @@ -34,6 +34,6 @@ class MoneyTypeTest extends LocalizedTestCase $form = $this->factory->create('money', null, array('currency' => 'JPY')); $view = $form->createView(); - $this->assertTrue((bool)strstr($view->get('money_pattern'), '¥')); + $this->assertTrue((Boolean) strstr($view->get('money_pattern'), '¥')); } } From c3f0ec74a15873a4c0e9b2fa13c8a15aff0a9fdd Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 28 Jan 2012 09:08:30 +0100 Subject: [PATCH 06/11] Make DoctrineBundle fowards compatible with Doctrine 2.2 --- .../Bundle/DoctrineBundle/Mapping/MetadataFactory.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Mapping/MetadataFactory.php b/src/Symfony/Bundle/DoctrineBundle/Mapping/MetadataFactory.php index fc8f8bad8b..b9c43b1385 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Mapping/MetadataFactory.php +++ b/src/Symfony/Bundle/DoctrineBundle/Mapping/MetadataFactory.php @@ -75,8 +75,8 @@ class MetadataFactory $all = $metadata->getMetadata(); if (class_exists($class)) { - $r = $all[0]->getReflectionClass(); - $path = $this->getBasePathForClass($class, $r->getNamespacename(), dirname($r->getFilename())); + $r = new \ReflectionClass($all[0]->name); + $path = $this->getBasePathForClass($class, $r->getNamespaceName(), dirname($r->getFilename())); $metadata->setNamespace($r->getNamespacename()); } elseif (!$path) { throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $class)); @@ -104,8 +104,8 @@ class MetadataFactory $all = $metadata->getMetadata(); if (class_exists($all[0]->name)) { - $r = $all[0]->getReflectionClass(); - $path = $this->getBasePathForClass($namespace, $r->getNamespacename(), dirname($r->getFilename())); + $r = new \ReflectionClass($all[0]->name); + $path = $this->getBasePathForClass($namespace, $r->getNamespaceName(), dirname($r->getFilename())); } elseif (!$path) { throw new \RuntimeException(sprintf('Unable to determine where to save the "%s" class (use the --path option).', $all[0]->name)); } From 9fa3201c11c2e843fd396532b628fd2b7ff464a6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 2 Feb 2012 10:00:42 +0100 Subject: [PATCH 07/11] removed unneeded code --- .../Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php index cfe7c965da..d7b99d240b 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php @@ -11,10 +11,7 @@ namespace Symfony\Tests\Component\Form\Extension\Core\Type; -use Symfony\Component\Form\FormFactory; - require_once __DIR__ . '/LocalizedTestCase.php'; -require_once __DIR__ . '/../../../../../../../../src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php'; class MoneyTypeTest extends LocalizedTestCase { From a1b6d4c46b43d8a798eeec5807670bf675917cb8 Mon Sep 17 00:00:00 2001 From: lsmith77 Date: Thu, 2 Feb 2012 18:09:32 +0100 Subject: [PATCH 08/11] Added a failing testcase for escaped % in array parameters --- .../DependencyInjection/ParameterBag/ParameterBagTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php index 1499927f8c..13908393aa 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php @@ -94,6 +94,7 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays'); $this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it'); $this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it'); + $this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %foo %bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it'); $bag = new ParameterBag(array('foo' => true)); $this->assertSame(true, $bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); From 045f93603810a1c386ba717dbf4b3c02d150a847 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 2 Feb 2012 18:24:41 +0100 Subject: [PATCH 09/11] Changed the testcase to expect the unescaping only after the resolution String values are not unescaped either in resolveValue() because it can be called several times for the same parameter. --- .../ParameterBag/ParameterBagTest.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php index 13908393aa..29eeb7489e 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php @@ -94,7 +94,7 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays'); $this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it'); $this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it'); - $this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %foo %bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it'); + $this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it'); $bag = new ParameterBag(array('foo' => true)); $this->assertSame(true, $bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); @@ -166,6 +166,22 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase } } + /** + * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve + */ + public function testResolveUnespacesValue() + { + $bag = new ParameterBag(array( + 'foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')), + 'bar' => 'I\'m a %%foo%%', + )); + + $bag->resolve(); + + $this->assertEquals('I\'m a %foo%', $bag->get('bar'), '->resolveValue() supports % escaping by doubling it'); + $this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it'); + } + /** * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve * @dataProvider stringsWithSpacesProvider From 8e13095e5c584e3f693c3789148440411df816a0 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 2 Feb 2012 18:26:12 +0100 Subject: [PATCH 10/11] Fixed the unescaping of parameters to handle arrays --- .../ParameterBag/ParameterBag.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php index c1eb9622c5..c895888bc9 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php @@ -139,7 +139,7 @@ class ParameterBag implements ParameterBagInterface foreach ($this->parameters as $key => $value) { try { $value = $this->resolveValue($value); - $parameters[$key] = is_string($value) ? str_replace('%%', '%', $value) : $value; + $parameters[$key] = $this->unescapeString($value); } catch (ParameterNotFoundException $e) { $e->setSourceKey($key); @@ -235,4 +235,22 @@ class ParameterBag implements ParameterBagInterface { return $this->resolved; } + + private function unescapeString($value) + { + if (is_string($value)) { + return str_replace('%%', '%', $value); + } + + if (is_array($value)) { + $result = array(); + foreach ($value as $k => $v) { + $result[$k] = $this->unescapeString($v); + } + + return $result; + } + + return $value; + } } From a7b48c058b50e221d469b7c137c05bfec7118688 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 2 Feb 2012 18:59:53 +0100 Subject: [PATCH 11/11] Renamed the method --- .../DependencyInjection/ParameterBag/ParameterBag.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php index c895888bc9..a6162aaf06 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php @@ -139,7 +139,7 @@ class ParameterBag implements ParameterBagInterface foreach ($this->parameters as $key => $value) { try { $value = $this->resolveValue($value); - $parameters[$key] = $this->unescapeString($value); + $parameters[$key] = $this->unescapeValue($value); } catch (ParameterNotFoundException $e) { $e->setSourceKey($key); @@ -236,7 +236,7 @@ class ParameterBag implements ParameterBagInterface return $this->resolved; } - private function unescapeString($value) + private function unescapeValue($value) { if (is_string($value)) { return str_replace('%%', '%', $value); @@ -245,7 +245,7 @@ class ParameterBag implements ParameterBagInterface if (is_array($value)) { $result = array(); foreach ($value as $k => $v) { - $result[$k] = $this->unescapeString($v); + $result[$k] = $this->unescapeValue($v); } return $result;