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 diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php index c1eb9622c5..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] = is_string($value) ? str_replace('%%', '%', $value) : $value; + $parameters[$key] = $this->unescapeValue($value); } catch (ParameterNotFoundException $e) { $e->setSourceKey($key); @@ -235,4 +235,22 @@ class ParameterBag implements ParameterBagInterface { return $this->resolved; } + + private function unescapeValue($value) + { + if (is_string($value)) { + return str_replace('%%', '%', $value); + } + + if (is_array($value)) { + $result = array(); + foreach ($value as $k => $v) { + $result[$k] = $this->unescapeValue($v); + } + + return $result; + } + + return $value; + } } 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/src/Symfony/Component/HttpKernel/HttpCache/Esi.php b/src/Symfony/Component/HttpKernel/HttpCache/Esi.php index e57b69c009..e1a0e6a271 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/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index 44d96793e3..56a5aa3128 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -45,6 +45,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 */ diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ParameterBag/ParameterBagTest.php index e2284572ad..6340d38e49 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->assertTrue($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings'); @@ -165,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 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..d7b99d240b 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/MoneyTypeTest.php @@ -24,4 +24,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((Boolean) strstr($view->get('money_pattern'), '¥')); + } } diff --git a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php index f7e7bc7343..5f178447ad 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/EsiTest.php @@ -114,6 +114,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 */