Merge branch '5.2' into 5.x

* 5.2:
  Fix rate limiter documentation
  Fix merge.
  fix lexing mapping values with trailing whitespaces
  [String] Fix Notice when argument is empty string
  [Inflector] Fix Notice when argument is empty string
  [Security] fix #39262, more defensive PasswordMigratingListener
  [Workflow] Fixed case when the marking store is not defined
  [Security] fix #39249, default entry_point compiler pass was returning too early
  Fix small typos
This commit is contained in:
Alexander M. Turek 2020-12-02 09:55:39 +01:00
commit e97f9e7d6e
13 changed files with 71 additions and 12 deletions

View File

@ -810,9 +810,7 @@ class FrameworkExtension extends Extension
// Create Workflow
$workflowDefinition = new ChildDefinition(sprintf('%s.abstract', $type));
$workflowDefinition->replaceArgument(0, new Reference(sprintf('%s.definition', $workflowId)));
if (isset($markingStoreDefinition)) {
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
}
$workflowDefinition->replaceArgument(1, $markingStoreDefinition ?? null);
$workflowDefinition->replaceArgument(3, $name);
$workflowDefinition->replaceArgument(4, $workflow['events_to_dispatch']);

View File

@ -226,7 +226,13 @@ abstract class FrameworkExtensionTest extends TestCase
$this->assertTrue($container->hasDefinition('workflow.article'), 'Workflow is registered as a service');
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.article')->getParent());
$this->assertNull($container->getDefinition('workflow.article')->getArgument('index_4'), 'Workflows has eventsToDispatch=null');
$args = $container->getDefinition('workflow.article')->getArguments();
$this->assertArrayHasKey('index_0', $args);
$this->assertArrayHasKey('index_1', $args);
$this->assertArrayHasKey('index_3', $args);
$this->assertArrayHasKey('index_4', $args);
$this->assertNull($args['index_4'], 'Workflows has eventsToDispatch=null');
$this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service');

View File

@ -50,7 +50,7 @@ class RegisterEntryPointPass implements CompilerPassInterface
}
if (!$entryPoints) {
return;
continue;
}
$config = $container->getDefinition('security.firewall.map.config.'.$firewallName);

View File

@ -10,8 +10,8 @@ CHANGELOG
5.0.0
-----
* Added argument `$selector` to ``Crawler::children()`
* Added argument `$default` to ``Crawler::text()` and `html()`
* Added argument `$selector` to `Crawler::children()`
* Added argument `$default` to `Crawler::text()` and `html()`
4.4.0
-----

View File

@ -323,4 +323,16 @@ class InflectorTest extends TestCase
$this->assertEquals($expectedPlural, $plural);
}
public function testPluralizeEmptyString()
{
$plural = Inflector::pluralize('');
$this->assertSame('', $plural);
}
public function testSingularizeEmptyString()
{
$singular = Inflector::singularize('');
$this->assertSame('', $singular);
}
}

View File

@ -25,7 +25,7 @@
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1",
"symfony/string": "^5.1"
"symfony/string": "~5.1.10|^5.2.1"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Inflector\\": "" },

View File

@ -20,13 +20,15 @@ $ composer require symfony/rate-limiter
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
use Symfony\Component\RateLimiter\RateLimiterFactory;
$limiter = new RateLimiterFactory([
$factory = new RateLimiterFactory([
'id' => 'login',
'policy' => 'token_bucket',
'limit' => 10,
'rate' => ['interval' => '15 minutes'],
], new InMemoryStorage());
$limiter = $factory->create();
// blocks until 1 token is free to use for this process
$limiter->reserve(1)->wait();
// ... execute the code

View File

@ -56,7 +56,12 @@ class PasswordMigratingListener implements EventSubscriberInterface
}
$passwordUpgrader = $badge->getPasswordUpgrader();
if (null === $passwordUpgrader) {
if (!$passport->hasBadge(UserBadge::class)) {
return;
}
/** @var UserBadge $userBadge */
$userBadge = $passport->getBadge(UserBadge::class);
$userLoader = $userBadge->getUserLoader();

View File

@ -24,6 +24,7 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgrade
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;
use Symfony\Component\Security\Http\EventListener\PasswordMigratingListener;
@ -67,6 +68,20 @@ class PasswordMigratingListenerTest extends TestCase
yield [$this->createEvent($this->createMock(PassportInterface::class))];
}
public function testUnsupportedPassport()
{
// A custom Passport, without an UserBadge
$passport = $this->createMock(UserPassportInterface::class);
$passport->method('getUser')->willReturn($this->user);
$passport->method('hasBadge')->withConsecutive([PasswordUpgradeBadge::class], [UserBadge::class])->willReturnOnConsecutiveCalls(true, false);
$passport->expects($this->once())->method('getBadge')->with(PasswordUpgradeBadge::class)->willReturn(new PasswordUpgradeBadge('pa$$word'));
// We should never "getBadge" for "UserBadge::class"
$event = $this->createEvent($passport);
$this->listener->onLoginSuccess($event);
}
public function testUpgradeWithUpgrader()
{
$passwordUpgrader = $this->createPasswordUpgrader();

View File

@ -305,6 +305,7 @@ final class EnglishInflector implements InflectorInterface
* A list of words which should not be inflected, reversed.
*/
private static $uninflected = [
'',
'atad',
'reed',
'kcabdeef',

View File

@ -306,4 +306,16 @@ class EnglishInflectorTest extends TestCase
{
$this->assertSame(\is_array($plural) ? $plural : [$plural], (new EnglishInflector())->pluralize($singular));
}
public function testPluralizeEmptyString()
{
$plural = (new EnglishInflector())->pluralize('');
$this->assertSame([''], $plural);
}
public function testSingularizeEmptyString()
{
$singular = (new EnglishInflector())->singularize('');
$this->assertSame([''], $singular);
}
}

View File

@ -761,10 +761,10 @@ class Parser
switch ($value[0] ?? '') {
case '"':
case "'":
$cursor = \strlen($this->currentLine) - \strlen($value);
$cursor = \strlen(rtrim($this->currentLine)) - \strlen(rtrim($value));
$parsedValue = Inline::parse($this->lexInlineQuotedString($cursor), $flags, $this->refs);
if (isset($this->currentLine[$cursor]) && preg_replace('/\s*#.*$/A', '', substr($this->currentLine, $cursor))) {
if (isset($this->currentLine[$cursor]) && preg_replace('/\s*(#.*)?$/A', '', substr($this->currentLine, $cursor))) {
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($this->currentLine, $cursor)));
}

View File

@ -2670,7 +2670,7 @@ YAML;
);
}
public function testMultipleWhitespaceAtEndOfLine()
public function testWhitespaceAtEndOfLine()
{
$yaml = "\nfoo:\n arguments: [ '@bar' ] \n";
$this->assertSame(
@ -2691,6 +2691,14 @@ YAML;
],
$this->parser->parse($yaml)
);
$this->assertSame(
[
'foo' => 'bar',
'foobar' => 'baz',
],
$this->parser->parse("foo: 'bar' \nfoobar: baz")
);
}
/**