Merge branch '2.8' into 3.3

* 2.8:
  fixed wrong description in a phpdoc
  19 digits VISA card numbers are valid
  [HttpKernel] Fixed test name
  [Debug] prevent infinite loop with faulty exception handlers
  Add the missing `enabled` session attribute
  [HttpKernel] Turn bad hosts into 400 instead of 500
This commit is contained in:
Nicolas Grekas 2018-01-13 15:02:56 +01:00
commit 07b5304268
7 changed files with 36 additions and 5 deletions

View File

@ -102,6 +102,7 @@
</xsd:complexType> </xsd:complexType>
<xsd:complexType name="session"> <xsd:complexType name="session">
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="storage-id" type="xsd:string" /> <xsd:attribute name="storage-id" type="xsd:string" />
<xsd:attribute name="handler-id" type="xsd:string" /> <xsd:attribute name="handler-id" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" /> <xsd:attribute name="name" type="xsd:string" />

View File

@ -28,7 +28,7 @@ class StringInput extends ArgvInput
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'; 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
*/ */
public function __construct($input) public function __construct($input)
{ {

View File

@ -592,6 +592,8 @@ class ErrorHandler
$handler = self::$reservedMemory = null; $handler = self::$reservedMemory = null;
$handlers = array(); $handlers = array();
$previousHandler = null;
$sameHandlerLimit = 10;
while (!is_array($handler) || !$handler[0] instanceof self) { while (!is_array($handler) || !$handler[0] instanceof self) {
$handler = set_exception_handler('var_dump'); $handler = set_exception_handler('var_dump');
@ -601,7 +603,14 @@ class ErrorHandler
break; break;
} }
restore_exception_handler(); 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) { foreach ($handlers as $h) {
set_exception_handler($h); set_exception_handler($h);

View File

@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
@ -66,7 +67,11 @@ class RouterListener implements EventSubscriberInterface
private function setCurrentRequest(Request $request = null) private function setCurrentRequest(Request $request = null)
{ {
if (null !== $request) { if (null !== $request) {
$this->context->fromRequest($request); try {
$this->context->fromRequest($request);
} catch (\UnexpectedValueException $e) {
throw new BadRequestHttpException($e->getMessage(), $e, $e->getCode());
}
} }
} }

View File

@ -185,4 +185,19 @@ class RouterListenerTest extends TestCase
$response = $kernel->handle($request); $response = $kernel->handle($request);
$this->assertSame(400, $response->getStatusCode()); $this->assertSame(400, $response->getStatusCode());
} }
/**
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
*/
public function testRequestWithBadHost()
{
$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, $this->requestStack, new RequestContext());
$listener->onKernelRequest($event);
}
} }

View File

@ -78,9 +78,9 @@ class CardSchemeValidator extends ConstraintValidator
'/^5[1-5][0-9]{14}$/', '/^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})$/', '/^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( 'VISA' => array(
'/^4([0-9]{12}|[0-9]{15})$/', '/^4([0-9]{12}|[0-9]{15}|[0-9]{18})$/',
), ),
); );

View File

@ -106,6 +106,7 @@ class CardSchemeValidatorTest extends ConstraintValidatorTestCase
array('VISA', '4111111111111111'), array('VISA', '4111111111111111'),
array('VISA', '4012888888881881'), array('VISA', '4012888888881881'),
array('VISA', '4222222222222'), array('VISA', '4222222222222'),
array('VISA', '4917610000000000003'),
array(array('AMEX', 'VISA'), '4111111111111111'), array(array('AMEX', 'VISA'), '4111111111111111'),
array(array('AMEX', 'VISA'), '378282246310005'), array(array('AMEX', 'VISA'), '378282246310005'),
array(array('JCB', 'MASTERCARD'), '5105105105105100'), array(array('JCB', 'MASTERCARD'), '5105105105105100'),