Skip to content

Commit 51ec885

Browse files
Merge branch '7.3' into 7.4
* 7.3: [ObjectMapper] handle non existing property errors Fix AsCronTask not passing arguments to command [HttpFoundation] Fix deprecation in tests on PHP 8.5 Fix typo [VarExporter] Dump implicit-nullable types as explicit to prevent the corresponding deprecation [DependencyInjection] CS fix Allow mixed root on CompoundConstraintTestCase validator [Serializer] Fix readonly property initialization from incorrect scope Update BrevoRequestParser.php [JsonPath] Improve escape sequence validation in name selector
2 parents 5d336dd + 42171a1 commit 51ec885

File tree

23 files changed

+301
-72
lines changed

23 files changed

+301
-72
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger;
4+
5+
use Symfony\Component\Console\Attribute\AsCommand;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputArgument;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Scheduler\Attribute\AsCronTask;
11+
12+
#[AsCronTask(expression: '* * * * *', schedule: 'dummy_command')]
13+
#[AsCronTask(expression: '0 * * * *', arguments: 'test', schedule: 'dummy_command')]
14+
#[AsCommand(name: 'test:dummy-command')]
15+
class DummyCommand extends Command
16+
{
17+
public static array $calls = [];
18+
19+
public function configure(): void
20+
{
21+
$this->addArgument('dummy-argument', InputArgument::OPTIONAL);
22+
}
23+
24+
public function execute(InputInterface $input, ?OutputInterface $output = null): int
25+
{
26+
self::$calls[__FUNCTION__][] = $input->getArgument('dummy-argument');
27+
28+
return Command::SUCCESS;
29+
}
30+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SchedulerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

1414
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyCommand;
1516
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummySchedule;
1617
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTask;
1718
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
@@ -88,6 +89,29 @@ public function testAutoconfiguredScheduler()
8889
$this->assertSame([['5', 6], ['7', 8]], $calls['attributesOnMethod']);
8990
}
9091

92+
public function testAutoconfiguredSchedulerCommand()
93+
{
94+
$container = self::getContainer();
95+
$container->set('clock', $clock = new MockClock('2023-10-26T08:59:59Z'));
96+
97+
$this->assertTrue($container->get('receivers')->has('scheduler_dummy_command'));
98+
$this->assertInstanceOf(SchedulerTransport::class, $cron = $container->get('receivers')->get('scheduler_dummy_command'));
99+
$bus = $container->get(MessageBusInterface::class);
100+
101+
$getCalls = static function (float $sleep) use ($clock, $cron, $bus) {
102+
DummyCommand::$calls = [];
103+
$clock->sleep($sleep);
104+
foreach ($cron->get() as $message) {
105+
$bus->dispatch($message->with(new ReceivedStamp('scheduler_dummy_command')));
106+
}
107+
108+
return DummyCommand::$calls;
109+
};
110+
111+
$this->assertSame([], $getCalls(0));
112+
$this->assertSame(['execute' => [0 => null, 1 => 'test']], $getCalls(1));
113+
}
114+
91115
public function testSchedulerWithCustomTransport()
92116
{
93117
$container = self::getContainer();

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Scheduler/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ services:
1616
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyTaskWithCustomReceiver:
1717
autoconfigure: true
1818

19+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\DummyCommand:
20+
autoconfigure: true
21+
1922
clock:
2023
synthetic: true
2124

src/Symfony/Component/DependencyInjection/Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
112112
$definition = substr_replace($definition, '53', 2, 2);
113113
$definition = substr_replace($definition, 'Child', 44, 0);
114114
}
115+
/** @var ChildDefinition $definition */
115116
$definition = unserialize($definition);
116-
/* @var ChildDefinition $definition */
117117
$definition->setParent($parent);
118118

119119
if (null !== $shared && !isset($definition->getChanges()['shared'])) {

src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testConstructorWithChunks()
3232

3333
$buffer = '';
3434
ob_start(function (string $chunk) use (&$buffer) {
35-
$buffer .= $chunk;
35+
return $buffer .= $chunk;
3636
});
3737
$callback();
3838

src/Symfony/Component/JsonPath/JsonPathUtils.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\JsonPath;
1313

1414
use Symfony\Component\JsonPath\Exception\InvalidArgumentException;
15+
use Symfony\Component\JsonPath\Exception\JsonCrawlerException;
1516
use Symfony\Component\JsonPath\Tokenizer\JsonPathToken;
1617
use Symfony\Component\JsonPath\Tokenizer\TokenType;
1718
use Symfony\Component\JsonStreamer\Read\Splitter;
@@ -86,6 +87,9 @@ public static function findSmallestDeserializableStringAndPath(array $tokens, mi
8687
];
8788
}
8889

90+
/**
91+
* @throws JsonCrawlerException When an invalid Unicode escape sequence occurs
92+
*/
8993
public static function unescapeString(string $str, string $quoteChar): string
9094
{
9195
if ('"' === $quoteChar) {
@@ -104,17 +108,16 @@ public static function unescapeString(string $str, string $quoteChar): string
104108
while (null !== $char = $str[++$i] ?? null) {
105109
if ('\\' === $char && isset($str[$i + 1])) {
106110
$result .= match ($str[$i + 1]) {
107-
'"' => '"',
108-
"'" => "'",
109111
'\\' => '\\',
110112
'/' => '/',
111-
'b' => "\b",
113+
'b' => "\x08",
112114
'f' => "\f",
113115
'n' => "\n",
114116
'r' => "\r",
115117
't' => "\t",
116118
'u' => self::unescapeUnicodeSequence($str, $i),
117-
default => $char.$str[$i + 1], // keep the backslash
119+
$quoteChar => $quoteChar,
120+
default => throw new JsonCrawlerException('', \sprintf('Invalid escape sequence "\\%s" in %s-quoted string', $str[$i + 1], "'" === $quoteChar ? 'single' : 'double')),
118121
};
119122

120123
++$i;
@@ -128,16 +131,11 @@ public static function unescapeString(string $str, string $quoteChar): string
128131

129132
private static function unescapeUnicodeSequence(string $str, int &$i): string
130133
{
131-
if (!isset($str[$i + 5])) {
132-
// not enough characters for Unicode escape, treat as literal
133-
return $str[$i];
134+
if (!isset($str[$i + 5]) || !ctype_xdigit(substr($str, $i + 2, 4))) {
135+
throw new JsonCrawlerException('', 'Invalid unicode escape sequence');
134136
}
135137

136138
$hex = substr($str, $i + 2, 4);
137-
if (!ctype_xdigit($hex)) {
138-
// invalid hex, treat as literal
139-
return $str[$i];
140-
}
141139

142140
$codepoint = hexdec($hex);
143141
// looks like a valid Unicode codepoint, string length is sufficient and it starts with \u

src/Symfony/Component/JsonPath/Tests/JsonCrawlerTest.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testEscapedDoubleQuotesInFieldName()
8686
{"a": {"b\\"c": 42}}
8787
JSON);
8888

89-
$result = $crawler->find("$['a']['b\\\"c']");
89+
$result = $crawler->find('$["a"]["b\"c"]');
9090

9191
$this->assertSame(42, $result[0]);
9292
}
@@ -641,10 +641,6 @@ public static function provideSingleQuotedStringProvider(): array
641641
"$['\\u65e5\\u672c']",
642642
['Japan'],
643643
],
644-
[
645-
"$['quote\"here']",
646-
['with quote'],
647-
],
648644
[
649645
"$['M\\u00fcller']",
650646
[],
@@ -658,7 +654,7 @@ public static function provideSingleQuotedStringProvider(): array
658654
['with tab'],
659655
],
660656
[
661-
"$['quote\\\"here']",
657+
"$['quote\"here']",
662658
['with quote'],
663659
],
664660
[
@@ -725,29 +721,6 @@ public static function provideFilterWithUnicodeProvider(): array
725721
];
726722
}
727723

728-
/**
729-
* @dataProvider provideInvalidUnicodeSequenceProvider
730-
*/
731-
public function testInvalidUnicodeSequencesAreProcessedAsLiterals(string $jsonPath)
732-
{
733-
$this->assertIsArray(self::getUnicodeDocumentCrawler()->find($jsonPath), 'invalid unicode sequence should be treated as literal and not throw');
734-
}
735-
736-
public static function provideInvalidUnicodeSequenceProvider(): array
737-
{
738-
return [
739-
[
740-
'$["test\uZZZZ"]',
741-
],
742-
[
743-
'$["test\u123"]',
744-
],
745-
[
746-
'$["test\u"]',
747-
],
748-
];
749-
}
750-
751724
/**
752725
* @dataProvider provideComplexUnicodePath
753726
*/

src/Symfony/Component/JsonPath/Tests/JsonPathComplianceTestSuiteTest.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,6 @@ final class JsonPathComplianceTestSuiteTest extends TestCase
148148
'index selector, leading 0',
149149
'index selector, -0',
150150
'index selector, leading -0',
151-
'name selector, double quotes, escaped line feed',
152-
'name selector, double quotes, invalid escaped single quote',
153-
'name selector, double quotes, question mark escape',
154-
'name selector, double quotes, bell escape',
155-
'name selector, double quotes, vertical tab escape',
156-
'name selector, double quotes, 0 escape',
157-
'name selector, double quotes, x escape',
158-
'name selector, double quotes, n escape',
159-
'name selector, double quotes, unicode escape no hex',
160-
'name selector, double quotes, unicode escape too few hex',
161-
'name selector, double quotes, unicode escape upper u',
162-
'name selector, double quotes, unicode escape upper u long',
163-
'name selector, double quotes, unicode escape plus',
164-
'name selector, double quotes, unicode escape brackets',
165-
'name selector, double quotes, unicode escape brackets long',
166-
'name selector, double quotes, single high surrogate',
167-
'name selector, double quotes, single low surrogate',
168-
'name selector, double quotes, high high surrogate',
169-
'name selector, double quotes, low low surrogate',
170-
'name selector, double quotes, supplementary surrogate',
171-
'name selector, double quotes, surrogate incomplete low',
172-
'name selector, single quotes, escaped backspace',
173-
'name selector, single quotes, escaped line feed',
174-
'name selector, single quotes, invalid escaped double quote',
175151
'slice selector, excessively large from value with negative step',
176152
'slice selector, step, min exact - 1',
177153
'slice selector, step, max exact + 1',

src/Symfony/Component/Mailer/Bridge/Brevo/Webhook/BrevoRequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function getRequestMatcher(): RequestMatcherInterface
3737
new IsJsonRequestMatcher(),
3838
// https://developers.brevo.com/docs/how-to-use-webhooks#securing-your-webhooks
3939
// localhost is added for testing
40-
new IpsRequestMatcher(['185.107.232.1/24', '1.179.112.1/20', '127.0.0.1']),
40+
new IpsRequestMatcher(['185.107.232.1/24', '1.179.112.1/20', '172.246.240.1/20', '127.0.0.1']),
4141
]);
4242
}
4343

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ObjectMapper\Exception;
13+
14+
/**
15+
* Thrown when a property cannot be found.
16+
*
17+
* @author Antoine Bluchet <[email protected]>
18+
*/
19+
class NoSuchPropertyException extends MappingException
20+
{
21+
}

0 commit comments

Comments
 (0)