From 3e47c7102859a438da996cbcde02c743952660d6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 Jan 2018 17:55:58 +0100 Subject: [PATCH 1/9] [HttpKernel] Turn bad hosts into 400 instead of 500 --- .../HttpKernel/EventListener/RouterListener.php | 7 ++++++- .../Tests/EventListener/RouterListenerTest.php | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php index 12cbd2b6a4..7cee6e8a76 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\RequestStack; @@ -96,7 +97,11 @@ class RouterListener implements EventSubscriberInterface private function setCurrentRequest(Request $request = null) { if (null !== $request && $this->request !== $request) { - $this->context->fromRequest($request); + try { + $this->context->fromRequest($request); + } catch (\UnexpectedValueException $e) { + throw new BadRequestHttpException($e->getMessage(), $e, $e->getCode()); + } } $this->request = $request; diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index 8376ba8f6f..a0882999a2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -155,4 +155,19 @@ class RouterListenerTest extends TestCase array(array(), 'Matched route "n/a".'), ); } + + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException + */ + public function testSubRequestWithBadHost() + { + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $request = Request::create('http://bad host %22/'); + $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + + $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + + $listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack); + $listener->onKernelRequest($event); + } } From a3149310ac716b944518e022d9b34590285f8388 Mon Sep 17 00:00:00 2001 From: Samuel ROZE Date: Wed, 10 Jan 2018 17:16:33 +0000 Subject: [PATCH 2/9] Add the missing `enabled` session attribute --- .../FrameworkBundle/Resources/config/schema/symfony-1.0.xsd | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index cfcfb34da8..3cc6646cde 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -104,6 +104,7 @@ + From 5f397f8dcfbaa42e4c32b3e82752293ee1ab37cb Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 Jan 2018 19:03:23 +0100 Subject: [PATCH 3/9] [Debug] prevent infinite loop with faulty exception handlers --- src/Symfony/Component/Debug/ErrorHandler.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 704075614c..c0f07e256d 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -561,6 +561,8 @@ class ErrorHandler $handler = self::$reservedMemory = null; $handlers = array(); + $previousHandler = null; + $sameHandlerLimit = 10; while (!is_array($handler) || !$handler[0] instanceof self) { $handler = set_exception_handler('var_dump'); @@ -570,7 +572,14 @@ class ErrorHandler break; } restore_exception_handler(); - array_unshift($handlers, $handler); + + if ($handler !== $previousHandler) { + array_unshift($handlers, $handler); + $previousHandler = $handler; + } elseif (0 === --$sameHandlerLimit) { + $handler = null; + break; + } } foreach ($handlers as $h) { set_exception_handler($h); From e366772c0635742a236eabff47de6af6903d4a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 11 Jan 2018 10:34:39 +0100 Subject: [PATCH 4/9] [HttpKernel] Fixed test name --- .../HttpKernel/Tests/EventListener/RouterListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index a0882999a2..83517f2d96 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -159,7 +159,7 @@ class RouterListenerTest extends TestCase /** * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException */ - public function testSubRequestWithBadHost() + public function testRequestWithBadHost() { $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); $request = Request::create('http://bad host %22/'); From 0b03631e7f8cb5f9dffe8def783040008199004c Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 10 Jan 2018 17:43:14 +0000 Subject: [PATCH 5/9] Don't right trim the deprecation message --- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php | 2 +- .../PhpUnit/Tests/DeprecationErrorHandler/default.phpt | 8 ++++---- .../weak_vendors_on_non_vendor.phpt | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index a108126a2e..d13fc14c0c 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -223,7 +223,7 @@ class DeprecationErrorHandler uasort($deprecations[$group], $cmp); foreach ($deprecations[$group] as $msg => $notices) { - echo "\n", rtrim($msg, '.'), ': ', $notices['count'], "x\n"; + echo "\n ", $notices['count'], 'x: ', $msg, "\n"; arsort($notices); diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt index cd73372487..39a3e98586 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt @@ -63,20 +63,20 @@ $foo->testNonLegacyBar(); --EXPECTF-- Unsilenced deprecation notices (3) -unsilenced foo deprecation: 2x + 2x: unsilenced foo deprecation 2x in FooTestCase::testLegacyFoo -unsilenced bar deprecation: 1x + 1x: unsilenced bar deprecation 1x in FooTestCase::testNonLegacyBar Remaining deprecation notices (1) -silenced bar deprecation: 1x + 1x: silenced bar deprecation 1x in FooTestCase::testNonLegacyBar Legacy deprecation notices (1) Other deprecation notices (1) -root deprecation: 1x + 1x: root deprecation diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt index 7568d54a9c..e20c7adf6b 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt @@ -55,20 +55,20 @@ $foo->testNonLegacyBar(); --EXPECTF-- Unsilenced deprecation notices (3) -unsilenced foo deprecation: 2x + 2x: unsilenced foo deprecation 2x in FooTestCase::testLegacyFoo -unsilenced bar deprecation: 1x + 1x: unsilenced bar deprecation 1x in FooTestCase::testNonLegacyBar Remaining deprecation notices (1) -silenced bar deprecation: 1x + 1x: silenced bar deprecation 1x in FooTestCase::testNonLegacyBar Legacy deprecation notices (1) Other deprecation notices (1) -root deprecation: 1x + 1x: root deprecation From efb8fa164ee01adbfc5ce180bddab6d18d5ec17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ch=C3=A1bek?= Date: Thu, 11 Jan 2018 11:25:41 +0100 Subject: [PATCH 6/9] Add missing @ in phpdoc return statement --- src/Symfony/Component/Cache/Adapter/AdapterInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/AdapterInterface.php b/src/Symfony/Component/Cache/Adapter/AdapterInterface.php index 274ebec1ef..41222c1ab5 100644 --- a/src/Symfony/Component/Cache/Adapter/AdapterInterface.php +++ b/src/Symfony/Component/Cache/Adapter/AdapterInterface.php @@ -31,7 +31,7 @@ interface AdapterInterface extends CacheItemPoolInterface /** * {@inheritdoc} * - * return \Traversable|CacheItem[] + * @return \Traversable|CacheItem[] */ public function getItems(array $keys = array()); } From a53cc5ce91893d384d8c34b55746254374359de6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 11 Jan 2018 18:07:52 +0100 Subject: [PATCH 7/9] 19 digits VISA card numbers are valid --- .../Component/Validator/Constraints/CardSchemeValidator.php | 4 ++-- .../Validator/Tests/Constraints/CardSchemeValidatorTest.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php index be54a0cf47..14369c2365 100644 --- a/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php @@ -79,9 +79,9 @@ class CardSchemeValidator extends ConstraintValidator '/^5[1-5][0-9]{14}$/', '/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/', ), - // All Visa card numbers start with a 4. New cards have 16 digits. Old cards have 13. + // All Visa card numbers start with a 4 and have a length of 13, 16, or 19 digits. 'VISA' => array( - '/^4([0-9]{12}|[0-9]{15})$/', + '/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/', ), ); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php index dbe5166451..e12d201be0 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php @@ -111,6 +111,7 @@ class CardSchemeValidatorTest extends AbstractConstraintValidatorTest array('VISA', '4111111111111111'), array('VISA', '4012888888881881'), array('VISA', '4222222222222'), + array('VISA', '4917610000000000003'), array(array('AMEX', 'VISA'), '4111111111111111'), array(array('AMEX', 'VISA'), '378282246310005'), array(array('JCB', 'MASTERCARD'), '5105105105105100'), From e52d977d124d008a13ff287147d2cf6b5f7688a3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 13 Jan 2018 10:54:37 +0100 Subject: [PATCH 8/9] fixed wrong description in a phpdoc --- src/Symfony/Component/Console/Input/StringInput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Input/StringInput.php b/src/Symfony/Component/Console/Input/StringInput.php index 4e4c4a28b6..754d712cc3 100644 --- a/src/Symfony/Component/Console/Input/StringInput.php +++ b/src/Symfony/Component/Console/Input/StringInput.php @@ -26,7 +26,7 @@ class StringInput extends ArgvInput const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'; /** - * @param string $input An array of parameters from the CLI (in the argv format) + * @param string $input A string representing the parameters from the CLI * @param InputDefinition $definition A InputDefinition instance * * @deprecated The second argument is deprecated as it does not work (will be removed in 3.0), use 'bind' method instead From e9bcd217df24e73df955b3f383b282d8e9daeb0a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 13 Jan 2018 15:03:33 +0100 Subject: [PATCH 9/9] fix merge --- .../HttpKernel/Tests/EventListener/RouterListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php index cb30d0f985..0d3c558546 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/RouterListenerTest.php @@ -167,7 +167,7 @@ class RouterListenerTest extends TestCase $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); - $listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack); + $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); $listener->onKernelRequest($event); } }