From 849f3ed7e92e04a1f72346769931deecddd4d67d Mon Sep 17 00:00:00 2001 From: alquerci Date: Mon, 10 Jun 2013 20:35:46 +0200 Subject: [PATCH 1/9] [Finder] Fix SplFileInfo::getContents isn't working with ssh2 protocol --- src/Symfony/Component/Finder/SplFileInfo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Finder/SplFileInfo.php b/src/Symfony/Component/Finder/SplFileInfo.php index e7e58f757c..d911fe06e8 100644 --- a/src/Symfony/Component/Finder/SplFileInfo.php +++ b/src/Symfony/Component/Finder/SplFileInfo.php @@ -65,7 +65,7 @@ class SplFileInfo extends \SplFileInfo public function getContents() { $level = error_reporting(0); - $content = file_get_contents($this->getRealpath()); + $content = file_get_contents($this->getPathname()); error_reporting($level); if (false === $content) { $error = error_get_last(); From de289d2cfd173ef802e2ca72151422c9b79ff0c8 Mon Sep 17 00:00:00 2001 From: Douglas Greenshields Date: Tue, 11 Jun 2013 12:21:03 +0100 Subject: [PATCH 2/9] [Form] corrected interface bind() method defined against in deprecation notice --- src/Symfony/Component/Form/Form.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index f1c8e5cc60..55d80c2f9f 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -649,11 +649,11 @@ class Form implements \IteratorAggregate, FormInterface * @throws FormException if the method of the request is not one of GET, POST or PUT * * @deprecated Deprecated since version 2.1, to be removed in 2.3. Use - * {@link FormConfigInterface::bind()} instead. + * {@link FormInterface::bind()} instead. */ public function bindRequest(Request $request) { - trigger_error('bindRequest() is deprecated since version 2.1 and will be removed in 2.3. Use FormConfigInterface::bind() instead.', E_USER_DEPRECATED); + trigger_error('bindRequest() is deprecated since version 2.1 and will be removed in 2.3. Use FormInterface::bind() instead.', E_USER_DEPRECATED); return $this->bind($request); } From 41399360e8ae8deb07ff49ea4ed2ea5b2abec3d9 Mon Sep 17 00:00:00 2001 From: Dmitrii Chekaliuk Date: Thu, 13 Jun 2013 02:54:36 +0300 Subject: [PATCH 3/9] [DomCrawler] Fix handling file:// without a host --- src/Symfony/Component/DomCrawler/Link.php | 2 +- src/Symfony/Component/DomCrawler/Tests/LinkTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 3a65148354..838e5f9023 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -120,7 +120,7 @@ class Link return $baseUri.$uri; } - $baseUri = preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri); + $baseUri = preg_replace('#^(.*?//[^/]*)(?:\/.*)?$#', '$1', $this->currentUri); // absolute path if ('/' === $uri[0]) { diff --git a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php index c1d6268a12..be1c22c3f4 100644 --- a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php @@ -118,6 +118,11 @@ class LinkTest extends \PHPUnit_Framework_TestCase array('../bar/./../../foo', 'http://localhost/bar/foo/', 'http://localhost/foo'), array('../../', 'http://localhost/', 'http://localhost/'), array('../../', 'http://localhost', 'http://localhost/'), + + array('/foo', 'file:///', 'file:///foo'), + array('/foo', 'file:///bar/baz', 'file:///foo'), + array('foo', 'file:///', 'file:///foo'), + array('foo', 'file:///bar/baz', 'file:///bar/foo'), ); } } From 8764944c69d3afbd0ee19d2b200f4f1f28211ee4 Mon Sep 17 00:00:00 2001 From: Matthew J Mucklo Date: Fri, 7 Jun 2013 14:35:54 -0700 Subject: [PATCH 4/9] fix issue where $_ENV contains array vals There are cases where $env or $_ENV can contain a value that is an array This will cause Process to throw an Array to String conversion exception Initially I submitted a patch of Process.php, however Fabien indicated that it shouldn't be fixed there (see below pull request). Before recently, a simple work around would be in php.ini to set: register_argc_argv = On However with recent changes, this seems to no longer work. Original pull request: https://github.com/symfony/symfony/pull/7354 See ticket https://github.com/symfony/symfony/issues/7196 --- src/Symfony/Component/Process/ProcessBuilder.php | 3 +++ .../Process/Tests/ProcessBuilderTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index c4ef31d311..151340d336 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -151,6 +151,9 @@ class ProcessBuilder $env = $this->env; } + // Process can not handle env values that are arrays + $env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env; + return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options); } } diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 53e403605b..1d46d71a57 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -45,6 +45,22 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase $_ENV = $snapshot; } + public function testProcessBuilderShouldNotPassEnvArrays() + { + $snapshot = $_ENV; + $_ENV = array('a' => array('b', 'c'), 'd' => 'e', 'f' => 'g'); + $expected = array('d' => 'e', 'f' => 'g'); + + $pb = new ProcessBuilder(); + $pb->add('a')->inheritEnvironmentVariables() + ->setEnv('d', 'e'); + $proc = $pb->getProcess(); + + $this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() removes array values from $_ENV'); + + $_ENV = $snapshot; + } + public function testInheritEnvironmentVarsByDefault() { $pb = new ProcessBuilder(); From 0991cd0b9df3158a23d8a95e2981e3cac3db74fc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Jun 2013 08:50:29 +0200 Subject: [PATCH 5/9] [Process] moved env check to the Process class (refs #8227) --- src/Symfony/Component/Process/Process.php | 19 ++++++++++++++----- .../Component/Process/ProcessBuilder.php | 3 --- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index ac92467574..ed4cccff3c 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -145,10 +145,7 @@ class Process $this->cwd = getcwd(); } if (null !== $env) { - $this->env = array(); - foreach ($env as $key => $value) { - $this->env[(binary) $key] = (binary) $value; - } + $this->setEnv($env); } else { $this->env = null; } @@ -890,13 +887,25 @@ class Process /** * Sets the environment variables. * + * An environment variable value should be a string. + * If it is an array, the variable is ignored. + * + * That happens in PHP when 'argv' is registered into + * the $_ENV array for instance. + * * @param array $env The new environment variables * * @return self The current Process instance */ public function setEnv(array $env) { - $this->env = $env; + // Process can not handle env values that are arrays + $env = array_filter($env, function ($value) { if (!is_array($value)) { return true; } }); + + $this->env = array(); + foreach ($env as $key => $value) { + $this->env[(binary) $key] = (binary) $value; + } return $this; } diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index 151340d336..c4ef31d311 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -151,9 +151,6 @@ class ProcessBuilder $env = $this->env; } - // Process can not handle env values that are arrays - $env = $env ? array_filter($env, function ($value) { if (!is_array($value)) { return true; } }) : $env; - return new Process($script, $this->cwd, $env, $this->stdin, $this->timeout, $options); } } From 842f3fa3d28d72910059d83e268a708a9005035d Mon Sep 17 00:00:00 2001 From: Tom Maguire Date: Mon, 10 Jun 2013 14:35:49 +0100 Subject: [PATCH 6/9] do not re-register commands each time a Console\Application is run --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index e478c51723..6df31ae69b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -27,6 +27,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; class Application extends BaseApplication { private $kernel; + private $commandsRegistered = false; /** * Constructor. @@ -65,7 +66,9 @@ class Application extends BaseApplication */ public function doRun(InputInterface $input, OutputInterface $output) { - $this->registerCommands(); + if (!$this->commandsRegistered) { + $this->registerCommands(); + } if (true === $input->hasParameterOption(array('--shell', '-s'))) { $shell = new Shell($this); @@ -87,5 +90,7 @@ class Application extends BaseApplication $bundle->registerCommands($this); } } + + $this->commandsRegistered = true; } } From 24a07fbab80ca7cd655f793a1f7fedcb0f92c3b8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Jun 2013 09:07:59 +0200 Subject: [PATCH 7/9] [FrameworkBundle] tweaked previous merge (refs #8242) --- src/Symfony/Bundle/FrameworkBundle/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 6df31ae69b..695c819015 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -68,6 +68,8 @@ class Application extends BaseApplication { if (!$this->commandsRegistered) { $this->registerCommands(); + + $this->commandsRegistered = true; } if (true === $input->hasParameterOption(array('--shell', '-s'))) { @@ -90,7 +92,5 @@ class Application extends BaseApplication $bundle->registerCommands($this); } } - - $this->commandsRegistered = true; } } From 6b715136c8aca719a14b142f996e7a56acbe9c7a Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Wed, 5 Jun 2013 16:35:05 +0200 Subject: [PATCH 8/9] fixed date type format pattern regex --- .../Form/Extension/Core/Type/DateType.php | 2 +- .../Extension/Core/Type/DateTypeTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 71ae631c67..648ab1b7e5 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -144,7 +144,7 @@ class DateType extends AbstractType // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy) // lookup various formats at http://userguide.icu-project.org/formatparse/datetime - if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) { + if (preg_match('/^([yMd]+)[^yMd]*([yMd]+)[^yMd]*([yMd]+)$/', $pattern)) { $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern); } else { // default fallback diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index c0d7da676b..6d4dd2c8a7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -267,6 +267,29 @@ class DateTypeTest extends LocalizedTestCase $this->assertEquals('06*2010*02', $form->getViewData()); } + /** + * @dataProvider provideDateFormats + */ + public function testDatePatternWithFormatOption($format, $pattern) + { + $form = $this->factory->create('date', null, array( + 'format' => $format, + )); + + $view = $form->createView(); + + $this->assertEquals($pattern, $view->vars['date_pattern']); + } + + public function provideDateFormats() + { + return array( + array('dMy', '{{ day }}{{ month }}{{ year }}'), + array('d-M-yyyy', '{{ day }}-{{ month }}-{{ year }}'), + array('M d y', '{{ month }} {{ day }} {{ year }}'), + ); + } + /** * This test is to check that the strings '0', '1', '2', '3' are no accepted * as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively. From bcbbb28f76d38faca80e2cd2fd661afc8001f7c9 Mon Sep 17 00:00:00 2001 From: Tiago Garcia Date: Tue, 4 Jun 2013 23:48:28 +0200 Subject: [PATCH 9/9] Throw exception if value is passed to VALUE_NONE input, long syntax --- src/Symfony/Component/Console/Input/ArgvInput.php | 6 +++++- .../Component/Console/Tests/Input/ArgvInputTest.php | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/ArgvInput.php b/src/Symfony/Component/Console/Input/ArgvInput.php index 0f9b62c53f..6c3267c9fd 100644 --- a/src/Symfony/Component/Console/Input/ArgvInput.php +++ b/src/Symfony/Component/Console/Input/ArgvInput.php @@ -134,7 +134,7 @@ class ArgvInput extends Input break; } else { - $this->addLongOption($option->getName(), true); + $this->addLongOption($option->getName(), null); } } } @@ -220,6 +220,10 @@ class ArgvInput extends Input $value = null; } + if (null !== $value && !$option->acceptValue()) { + throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value)); + } + if (null === $value && $option->acceptValue() && count($this->parsed)) { // if option accepts an optional or mandatory argument // let's see if there is one provided diff --git a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php index 472a91580c..532841c0b0 100644 --- a/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php +++ b/src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php @@ -105,6 +105,15 @@ class ArgvInputTest extends \PHPUnit_Framework_TestCase $this->assertEquals('The "-o" option does not exist.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one'); } + try { + $input = new ArgvInput(array('cli.php', '--foo=bar')); + $input->bind(new InputDefinition(array(new InputOption('foo', 'f', InputOption::VALUE_NONE)))); + $this->fail('->parse() throws a \RuntimeException if a value is passed to an option which does not take one'); + } catch (\Exception $e) { + $this->assertInstanceOf('\RuntimeException', $e, '->parse() throws a \RuntimeException if a value is passed to an option which does not take one'); + $this->assertEquals('The "--foo" option does not accept a value.', $e->getMessage(), '->parse() throws a \RuntimeException if a value is passed to an option which does not take one'); + } + try { $input = new ArgvInput(array('cli.php', 'foo', 'bar')); $input->bind(new InputDefinition());