From 7e5191375b5e2e32e1ae54bb7716042cf05e0391 Mon Sep 17 00:00:00 2001 From: Aaron Stephens Date: Tue, 28 Jan 2014 16:56:56 +0000 Subject: [PATCH 1/4] Fixed data in pipe being truncated if not read before process termination --- .../Component/Process/ProcessPipes.php | 8 ++++-- .../Process/Tests/AbstractProcessTest.php | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Process/ProcessPipes.php b/src/Symfony/Component/Process/ProcessPipes.php index c35d7bc96b..67b11e615b 100644 --- a/src/Symfony/Component/Process/ProcessPipes.php +++ b/src/Symfony/Component/Process/ProcessPipes.php @@ -289,9 +289,13 @@ class ProcessPipes foreach ($r as $pipe) { $type = array_search($pipe, $this->pipes); - $data = fread($pipe, 8192); - if (strlen($data) > 0) { + $data = ''; + while ($dataread = fread($pipe, 8192)) { + $data .= $dataread; + } + + if ($data) { $read[$type] = $data; } diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index b5b34b2197..6401ec33e4 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -80,6 +80,32 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertLessThan(1.8, $duration); } + public function testAllOutputIsActuallyReadOnTermination() + { + // this code will result in a maximum of 2 reads of 8192 bytes by calling + // start() and isRunning(). by the time getOutput() is called the process + // has terminated so the internal pipes array is already empty. normally + // the call to start() will not read any data as the process will not have + // generated output, but this is non-deterministic so we must count it as + // a possibility. therefore we need 2 * 8192 plus another byte which will + // never be read. + $expectedOutputSize = 16385; + + $code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize); + $p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code))); + + $p->start(); + usleep(250000); + + if ($p->isRunning()) { + $this->fail('Process execution did not complete in the required time frame'); + } + + $o = $p->getOutput(); + + $this->assertEquals($expectedOutputSize, strlen($o)); + } + public function testCallbacksAreExecutedWithStart() { $data = ''; From 6498518925a1917c78157010584329d2cf70dbad Mon Sep 17 00:00:00 2001 From: Luis Cordova Date: Wed, 12 Mar 2014 20:16:46 -0500 Subject: [PATCH 2/4] prefixed http:// to url output on server:run command in order to make it clickable --- src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index 1d01e04c12..d2255e50be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -90,7 +90,7 @@ EOF ->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env)) ; - $output->writeln(sprintf("Server running on %s\n", $input->getArgument('address'))); + $output->writeln(sprintf("Server running on http://%s\n", $input->getArgument('address'))); $builder = new ProcessBuilder(array(PHP_BINARY, '-S', $input->getArgument('address'), $router)); $builder->setWorkingDirectory($input->getOption('docroot')); From 34720c921eacd2a94dd47b3a516426aa059ead47 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Tue, 11 Mar 2014 17:36:00 +0000 Subject: [PATCH 3/4] convertDomElementToArray should handle zero values --- src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php | 1 + src/Symfony/Component/Config/Util/XmlUtils.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php index feb796b68f..722c4db144 100644 --- a/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php +++ b/src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php @@ -80,6 +80,7 @@ class XmlUtilsTest extends \PHPUnit_Framework_TestCase array(array('foo' => null), ''), array(array('foo' => 'bar'), 'bar'), array(array('foo' => array('foo' => 'bar')), ''), + array(array('foo' => array('foo' => 0)), '0'), array(array('foo' => array('foo' => 'bar')), 'bar'), array(array('foo' => array('foo' => 'bar', 'value' => 'text')), 'text'), array(array('foo' => array('attr' => 'bar', 'foo' => 'text')), 'text'), diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index f2ea98beed..494d7c3895 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -132,7 +132,7 @@ class XmlUtils $nodeValue = false; foreach ($element->childNodes as $node) { if ($node instanceof \DOMText) { - if (trim($node->nodeValue)) { + if (strlen(trim($node->nodeValue)) > 0) { $nodeValue = trim($node->nodeValue); $empty = false; } From cbc2f9fd369be6d427fe0ce23d960d842203e92d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Mar 2014 06:07:25 +0100 Subject: [PATCH 4/4] [Config] made a condition more explicit --- src/Symfony/Component/Config/Util/XmlUtils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Util/XmlUtils.php b/src/Symfony/Component/Config/Util/XmlUtils.php index 494d7c3895..e7c0bf79d4 100644 --- a/src/Symfony/Component/Config/Util/XmlUtils.php +++ b/src/Symfony/Component/Config/Util/XmlUtils.php @@ -132,7 +132,7 @@ class XmlUtils $nodeValue = false; foreach ($element->childNodes as $node) { if ($node instanceof \DOMText) { - if (strlen(trim($node->nodeValue)) > 0) { + if ('' !== trim($node->nodeValue)) { $nodeValue = trim($node->nodeValue); $empty = false; }