From 9d1004b59e0e741fecbd954af04919ff7001a1ce Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Mon, 8 Jul 2013 14:02:04 +0200 Subject: [PATCH 1/9] fix handling of a default 'template' as a string --- .../Fragment/HIncludeFragmentRenderer.php | 6 +++++- .../Fragment/HIncludeFragmentRendererTest.php | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index fafa76368c..92c4cecdc9 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -99,7 +99,11 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer private function templateExists($template) { if ($this->templating instanceof EngineInterface) { - return $this->templating->exists($template); + try { + return $this->templating->exists($template); + } catch (\InvalidArgumentException $e) { + return false; + } } $loader = $this->templating->getLoader(); diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php index 1e77374901..89bf12eb35 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -50,7 +50,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase $this->assertEquals('', $strategy->render('/foo', Request::create('/'))->getContent()); } - public function testRenderWhithDefault() + public function testRenderWithDefault() { // only default $strategy = new HIncludeFragmentRenderer(); @@ -64,4 +64,17 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase $strategy = new HIncludeFragmentRenderer(null, null, 'global_default'); $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent()); } -} + + public function testRenderWithDefaultText() + { + $engine = $this->getMock('Symfony\\Component\\Templating\\EngineInterface'); + $engine->expects($this->once()) + ->method('exists') + ->with('default') + ->will($this->throwException(new \InvalidArgumentException())); + + // only default + $strategy = new HIncludeFragmentRenderer($engine); + $this->assertEquals('default', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent()); + } +} \ No newline at end of file From 40591b92c8ef73aabc3be72ebe6389946fa2bb21 Mon Sep 17 00:00:00 2001 From: Reen Lokum Date: Mon, 8 Jul 2013 16:24:02 +0200 Subject: [PATCH 2/9] Comment fixed: RedrawFrequency is measured in steps. --- src/Symfony/Component/Console/Helper/ProgressHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index 25736af634..2fac7f0f79 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -167,7 +167,7 @@ class ProgressHelper extends Helper /** * Sets the redraw frequency. * - * @param int $freq The frequency in seconds + * @param int $freq The frequency in steps */ public function setRedrawFrequency($freq) { From 91bb7578c287fa82bf470667776e3a4bd603eacd Mon Sep 17 00:00:00 2001 From: Reen Lokum Date: Mon, 8 Jul 2013 16:34:53 +0200 Subject: [PATCH 3/9] ProgressHelper shows percentage complete. In the past the value was rounded, the progressbar ended up being 100% for 0.5% of the total execution time. That means 18 seconds on a 1 hour process. --- .../Component/Console/Helper/ProgressHelper.php | 5 ++--- .../Console/Tests/Helper/ProgressHelperTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index 2fac7f0f79..56507b869b 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -309,12 +309,11 @@ class ProgressHelper extends Helper $vars = array(); $percent = 0; if ($this->max > 0) { - $percent = (double) round($this->current / $this->max, 2); + $percent = (double) $this->current / $this->max; } if (isset($this->formatVars['bar'])) { $completeBars = 0; - $emptyBars = 0; if ($this->max > 0) { $completeBars = floor($percent * $this->barWidth); } else { @@ -349,7 +348,7 @@ class ProgressHelper extends Helper } if (isset($this->formatVars['percent'])) { - $vars['percent'] = str_pad($percent * 100, $this->widths['percent'], ' ', STR_PAD_LEFT); + $vars['percent'] = str_pad(floor($percent * 100), $this->widths['percent'], ' ', STR_PAD_LEFT); } return $vars; diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php index b5560263f6..f840ab1e80 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php @@ -74,6 +74,18 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase $this->assertEquals($this->generateOutput(' 0/50 [>---------------------------] 0%').$this->generateOutput(' 1/50 [>---------------------------] 2%').$this->generateOutput(' 2/50 [=>--------------------------] 4%'), stream_get_contents($output->getStream())); } + public function testPercentNotHundredBeforeComplete() + { + $progress = new ProgressHelper(); + $progress->start($output = $this->getOutputStream(), 200); + $progress->display(); + $progress->advance(199); + $progress->advance(); + + rewind($output->getStream()); + $this->assertEquals($this->generateOutput(' 0/200 [>---------------------------] 0%').$this->generateOutput(' 199/200 [===========================>] 99%').$this->generateOutput(' 200/200 [============================] 100%'), stream_get_contents($output->getStream())); + } + protected function getOutputStream() { return new StreamOutput(fopen('php://memory', 'r+', false)); From 06b69b859ac41696e0e08e899459cda3c218da54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 10 Jul 2013 09:16:02 +0200 Subject: [PATCH 4/9] fixed inline fragment renderer --- .../Component/HttpKernel/Fragment/InlineFragmentRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php index f17a3556c7..a4dab4c7d0 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php @@ -55,7 +55,7 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer $attributes = $reference->attributes; $reference->attributes = array(); $uri = $this->generateFragmentUri($uri, $request); - $reference->attributes = $attributes; + $reference->attributes = array_merge($attributes, $reference->attributes); } $subRequest = $this->createSubRequest($uri, $request); From 2dc1ee04b4c9c4a768f0cdb592a93078046d0359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 10 Jul 2013 16:02:46 +0200 Subject: [PATCH 5/9] [HtppKernel] fixed inline fragment renderer --- .../HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php index 2da3c80677..e13bcb4226 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php @@ -50,7 +50,7 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase $object = new \stdClass(); $subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller'); - $subRequest->attributes->replace(array('object' => $object)); + $subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller')); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $kernel From aaa40e5902cd614130145484b0731bf66d8ad58c Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Wed, 10 Jul 2013 10:46:48 +0000 Subject: [PATCH 6/9] Fixing configuration validation error messages. The min and max validation functions lead to incorrect error messages. --- src/Symfony/Component/Config/Definition/NumericNode.php | 4 ++-- .../Definition/Builder/NumericNodeDefinitionTest.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/NumericNode.php b/src/Symfony/Component/Config/Definition/NumericNode.php index df45f2ebef..f062ae07cc 100644 --- a/src/Symfony/Component/Config/Definition/NumericNode.php +++ b/src/Symfony/Component/Config/Definition/NumericNode.php @@ -39,10 +39,10 @@ class NumericNode extends ScalarNode $errorMsg = null; if (isset($this->min) && $value < $this->min) { - $errorMsg = sprintf('The value %s is too small for path "%s". Should be greater than: %s', $value, $this->getPath(), $this->min); + $errorMsg = sprintf('The value %s is too small for path "%s". Should be greater than or equal to %s', $value, $this->getPath(), $this->min); } if (isset($this->max) && $value > $this->max) { - $errorMsg = sprintf('The value %s is too big for path "%s". Should be less than: %s', $value, $this->getPath(), $this->max); + $errorMsg = sprintf('The value %s is too big for path "%s". Should be less than or equal to %s', $value, $this->getPath(), $this->max); } if (isset($errorMsg)) { $ex = new InvalidConfigurationException($errorMsg); diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php index 1cb08f90e9..cf0813ace0 100755 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/NumericNodeDefinitionTest.php @@ -39,7 +39,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than: 5 + * @expectedExceptionMessage The value 4 is too small for path "foo". Should be greater than or equal to 5 */ public function testIntegerMinAssertion() { @@ -49,7 +49,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than: 3 + * @expectedExceptionMessage The value 4 is too big for path "foo". Should be less than or equal to 3 */ public function testIntegerMaxAssertion() { @@ -66,7 +66,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than: 500 + * @expectedExceptionMessage The value 400 is too small for path "foo". Should be greater than or equal to 500 */ public function testFloatMinAssertion() { @@ -76,7 +76,7 @@ class NumericNodeDefinitionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than: 0.3 + * @expectedExceptionMessage The value 4.3 is too big for path "foo". Should be less than or equal to 0.3 */ public function testFloatMaxAssertion() { From 9c5f8c6b96faa48b9a2724bd3136e9c14f909aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Thu, 11 Jul 2013 11:21:24 +0200 Subject: [PATCH 7/9] [Yaml] removed wrong comment removal inside a string block --- src/Symfony/Component/Yaml/Parser.php | 6 +- .../Component/Yaml/Tests/ParserTest.php | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 4a82b784bc..017a32a227 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -304,14 +304,16 @@ class Parser $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine); - while ($this->moveToNextLine()) { + // We are in string block (ie. after a line ending with "|") + $removeComments = !preg_match('~(.*)\|[\s]*$~', $this->currentLine); + while ($this->moveToNextLine()) { if ($isItUnindentedCollection && !$this->isStringUnIndentedCollectionItem($this->currentLine)) { $this->moveToPreviousLine(); break; } - if ($this->isCurrentLineEmpty()) { + if ($removeComments && $this->isCurrentLineEmpty() || $this->isCurrentLineBlank()) { if ($this->isCurrentLineBlank()) { $data[] = substr($this->currentLine, $newIndent); } diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index a8d28b9131..a74bd3ee87 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -522,6 +522,63 @@ EOF; $this->assertEquals(array('hash' => null), Yaml::parse($input)); } + + public function testStringBlockWithComments() + { + $this->assertEquals(array('content' => << +

title

+ + +footer # comment3 +EOT + ), Yaml::parse(<< +

title

+ + + footer # comment3 +EOF + )); + } + + public function testNestedStringBlockWithComments() + { + $this->assertEquals(array(array('content' => << +

title

+ + +footer # comment3 +EOT + )), Yaml::parse(<< +

title

+ + + footer # comment3 +EOF + )); + } } class B From 306b704bb003c1250454b4417cab400b232ab036 Mon Sep 17 00:00:00 2001 From: Moritz Borgmann Date: Thu, 11 Jul 2013 16:47:09 +0200 Subject: [PATCH 8/9] Just a Typo --- .../Security/Http/Firewall/AbstractAuthenticationListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php index 80f47f7581..d33c0f7344 100644 --- a/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php @@ -156,7 +156,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface /** * Whether this request requires authentication. * - * The default implementation only processed requests to a specific path, + * The default implementation only processes requests to a specific path, * but a subclass could change this to only authenticate requests where a * certain parameters is present. * From bb59f401783d85ddbc654d597acc72630ed0d9a2 Mon Sep 17 00:00:00 2001 From: Brian Corrigan Date: Thu, 11 Jul 2013 15:02:43 -0400 Subject: [PATCH 9/9] Reverts JSON_NUMERIC_CHECK We shouldn't be coercing types. --- src/Symfony/Component/HttpFoundation/JsonResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 40ea08bc75..8fe757535d 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -83,7 +83,7 @@ class JsonResponse extends Response public function setData($data = array()) { // Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML. - $this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_NUMERIC_CHECK); + $this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT ); return $this->update(); }