Merge branch '3.1'
* 3.1: Minor fixes & cleanups [DependencyInjection] Add missing PHPDoc type Correct a typo in the ReflectionExtractor's description [HttpFoundation] JSONP callback validation [Console] Improved the explanation of the hasOption() method Uniformize exception vars according to our CS add missing use statement bug #18042 [Security] $attributes can be anything, but RoleVoter assumes strings
This commit is contained in:
commit
117bd4c305
@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
class AddConstraintValidatorsPass implements CompilerPassInterface
|
||||
{
|
||||
|
@ -281,6 +281,9 @@ class InputDefinition
|
||||
/**
|
||||
* Returns true if an InputOption object exists by name.
|
||||
*
|
||||
* This method can't be used to check if the user included the option when
|
||||
* executing the command (use getOption() instead).
|
||||
*
|
||||
* @param string $name The InputOption name
|
||||
*
|
||||
* @return bool true if the InputOption object exists, false otherwise
|
||||
|
@ -668,7 +668,7 @@ class Definition
|
||||
/**
|
||||
* Sets autowired.
|
||||
*
|
||||
* @param $autowired
|
||||
* @param bool $autowired
|
||||
*
|
||||
* @return Definition The current instance
|
||||
*/
|
||||
|
@ -89,11 +89,19 @@ class JsonResponse extends Response
|
||||
public function setCallback($callback = null)
|
||||
{
|
||||
if (null !== $callback) {
|
||||
// taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
|
||||
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
|
||||
// partially token from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
|
||||
// partially token from https://github.com/willdurand/JsonpCallbackValidator
|
||||
// JsonpCallbackValidator is released under the MIT License. See https://github.com/willdurand/JsonpCallbackValidator/blob/v1.1.0/LICENSE for details.
|
||||
// (c) William Durand <william.durand1@gmail.com>
|
||||
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*(?:\[(?:"(?:\\\.|[^"\\\])*"|\'(?:\\\.|[^\'\\\])*\'|\d+)\])*?$/u';
|
||||
$reserved = array(
|
||||
'break', 'do', 'instanceof', 'typeof', 'case', 'else', 'new', 'var', 'catch', 'finally', 'return', 'void', 'continue', 'for', 'switch', 'while',
|
||||
'debugger', 'function', 'this', 'with', 'default', 'if', 'throw', 'delete', 'in', 'try', 'class', 'enum', 'extends', 'super', 'const', 'export',
|
||||
'import', 'implements', 'let', 'private', 'public', 'yield', 'interface', 'package', 'protected', 'static', 'null', 'true', 'false',
|
||||
);
|
||||
$parts = explode('.', $callback);
|
||||
foreach ($parts as $part) {
|
||||
if (!preg_match($pattern, $part)) {
|
||||
if (!preg_match($pattern, $part) || in_array($part, $reserved, true)) {
|
||||
throw new \InvalidArgumentException('The callback name is not valid.');
|
||||
}
|
||||
}
|
||||
|
@ -231,6 +231,14 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
JsonResponse::create($serializable);
|
||||
}
|
||||
|
||||
public function testSetComplexCallback()
|
||||
{
|
||||
$response = JsonResponse::create(array('foo' => 'bar'));
|
||||
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
|
||||
|
||||
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
|
||||
}
|
||||
}
|
||||
|
||||
if (interface_exists('JsonSerializable')) {
|
||||
|
@ -197,7 +197,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
// Use a ReflectionProperty instead of $class to get the parent class if applicable
|
||||
try {
|
||||
$reflectionProperty = new \ReflectionProperty($class, $property);
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
} catch (\ReflectionException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
) {
|
||||
break;
|
||||
}
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
} catch (\ReflectionException $e) {
|
||||
// Try the next prefix if the method doesn't exist
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\Type;
|
||||
|
||||
/**
|
||||
* Extracts PHP informations using the reflection API.
|
||||
* Extracts data using the reflection API.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
@ -52,7 +52,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
||||
{
|
||||
try {
|
||||
$reflectionClass = new \ReflectionClass($class);
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
} catch (\ReflectionException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
||||
$reflectionProperty = new \ReflectionProperty($class, $property);
|
||||
|
||||
return $reflectionProperty->isPublic();
|
||||
} catch (\ReflectionException $reflectionExcetion) {
|
||||
} catch (\ReflectionException $e) {
|
||||
// Return false if the property doesn't exist
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
||||
if (0 === $reflectionMethod->getNumberOfRequiredParameters()) {
|
||||
return array($reflectionMethod, $prefix);
|
||||
}
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
} catch (\ReflectionException $e) {
|
||||
// Return null if the property doesn't exist
|
||||
}
|
||||
}
|
||||
@ -331,8 +331,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
||||
if ($reflectionMethod->getNumberOfParameters() >= 1) {
|
||||
return array($reflectionMethod, $prefix);
|
||||
}
|
||||
} catch (\ReflectionException $reflectionException) {
|
||||
// Try the next one if method does not exist
|
||||
} catch (\ReflectionException $e) {
|
||||
// Try the next prefix if the method doesn't exist
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Security\Core\Authorization\Voter;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Role\RoleInterface;
|
||||
|
||||
/**
|
||||
* RoleVoter votes if any attribute starts with a given prefix.
|
||||
@ -41,7 +42,11 @@ class RoleVoter implements VoterInterface
|
||||
$roles = $this->extractRoles($token);
|
||||
|
||||
foreach ($attributes as $attribute) {
|
||||
if (0 !== strpos($attribute, $this->prefix)) {
|
||||
if ($attribute instanceof RoleInterface) {
|
||||
$attribute = $attribute->getRole();
|
||||
}
|
||||
|
||||
if (!is_string($attribute) || 0 !== strpos($attribute, $this->prefix)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,12 @@ class RoleVoterTest extends \PHPUnit_Framework_TestCase
|
||||
array(array('ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
|
||||
array(array('ROLE_FOO'), array('FOO', 'ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
|
||||
array(array('ROLE_BAR', 'ROLE_FOO'), array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
|
||||
|
||||
// Test mixed Types
|
||||
array(array(), array(array()), VoterInterface::ACCESS_ABSTAIN),
|
||||
array(array(), array(new \stdClass()), VoterInterface::ACCESS_ABSTAIN),
|
||||
array(array('ROLE_BAR'), array(new Role('ROLE_BAR')), VoterInterface::ACCESS_GRANTED),
|
||||
array(array('ROLE_BAR'), array(new Role('ROLE_FOO')), VoterInterface::ACCESS_DENIED),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ class ReflectionCaster
|
||||
if (isset($a[$prefix.'returnType'])) {
|
||||
$v = $a[$prefix.'returnType'];
|
||||
$v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||
$a[$prefix.'returnType'] = new ClassStub(($a[$prefix.'returnType']->allowsNull() ? '?' : '').$v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
|
||||
$a[$prefix.'returnType'] = new ClassStub($a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v, array(class_exists($v, false) || interface_exists($v, false) || trait_exists($v, false) ? $v : '', ''));
|
||||
}
|
||||
if (isset($a[$prefix.'class'])) {
|
||||
$a[$prefix.'class'] = new ClassStub($a[$prefix.'class']);
|
||||
@ -221,21 +221,12 @@ class ReflectionCaster
|
||||
'allowsNull' => 'allowsNull',
|
||||
));
|
||||
|
||||
try {
|
||||
if (method_exists($c, 'getType')) {
|
||||
if ($v = $c->getType()) {
|
||||
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||
}
|
||||
} else {
|
||||
$v = explode(' ', $c->__toString(), 6);
|
||||
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
|
||||
$a[$prefix.'typeHint'] = $v[4];
|
||||
}
|
||||
}
|
||||
} catch (\ReflectionException $e) {
|
||||
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
|
||||
$a[$prefix.'typeHint'] = $m[1];
|
||||
if (method_exists($c, 'getType')) {
|
||||
if ($v = $c->getType()) {
|
||||
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
|
||||
}
|
||||
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $c, $v)) {
|
||||
$a[$prefix.'typeHint'] = $v[1];
|
||||
}
|
||||
|
||||
if (isset($a[$prefix.'typeHint'])) {
|
||||
|
Reference in New Issue
Block a user