Skip to content

Commit f18d5bb

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date [ExpressionLanguage] Improve test coverage [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent [Security] consistent singular/plural translation in Dutch reset the validation context after validating nested constraints do not duplicate directory separators fix handling empty data in ValueToDuplicatesTransformer [Validator] review latvian translations [Validator] Add Dutch translation for `WordCount` constraint allow more unicode characters in URL paths [String][EnglishInflector] Fix words ending in 'le', e.g., articles do not duplicate directory separators [Uid] Ensure UuidV1 is created in lowercase
2 parents a4fc289 + bae6fa5 commit f18d5bb

File tree

27 files changed

+290
-20
lines changed

27 files changed

+290
-20
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testGenerateFragmentUri()
7171
'index' => sprintf(<<<TWIG
7272
{{ fragment_uri(controller("%s::templateAction", {template: "foo.html.twig"})) }}
7373
TWIG
74-
, TemplateController::class), ]);
74+
, str_replace('\\', '\\\\', TemplateController::class)), ]);
7575
$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
7676
$twig->addExtension(new HttpKernelExtension());
7777

@@ -81,7 +81,7 @@ public function testGenerateFragmentUri()
8181
]);
8282
$twig->addRuntimeLoader($loader);
8383

84-
$this->assertSame('/_fragment?_hash=PP8%2FeEbn1pr27I9wmag%2FM6jYGVwUZ0l2h0vhh2OJ6CI%3D&amp;_path=template%3Dfoo.html.twig%26_format%3Dhtml%26_locale%3Den%26_controller%3DSymfonyBundleFrameworkBundleControllerTemplateController%253A%253AtemplateAction', $twig->render('index'));
84+
$this->assertSame('/_fragment?_hash=XCg0hX8QzSwik8Xuu9aMXhoCeI4oJOob7lUVacyOtyY%3D&amp;_path=template%3Dfoo.html.twig%26_format%3Dhtml%26_locale%3Den%26_controller%3DSymfony%255CBundle%255CFrameworkBundle%255CController%255CTemplateController%253A%253AtemplateAction', $twig->render('index'));
8585
}
8686

8787
protected function getFragmentHandler($returnOrException): FragmentHandler

src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public function panelAction(string $token): Response
8383
*/
8484
private function getTraces(RequestDataCollector $request, string $method): array
8585
{
86-
$traceRequest = Request::create(
87-
$request->getPathInfo(),
88-
$request->getRequestServer(true)->get('REQUEST_METHOD'),
89-
\in_array($request->getMethod(), ['DELETE', 'PATCH', 'POST', 'PUT'], true) ? $request->getRequestRequest()->all() : $request->getRequestQuery()->all(),
86+
$traceRequest = new Request(
87+
$request->getRequestQuery()->all(),
88+
$request->getRequestRequest()->all(),
89+
$request->getRequestAttributes()->all(),
9090
$request->getRequestCookies(true)->all(),
9191
[],
9292
$request->getRequestServer(true)->all()
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Bundle\WebProfilerBundle\Tests\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
15+
use Symfony\Bundle\FrameworkBundle\Routing\Router;
16+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
17+
use Symfony\Bundle\WebProfilerBundle\Tests\Functional\WebProfilerBundleKernel;
18+
use Symfony\Component\DomCrawler\Crawler;
19+
use Symfony\Component\Routing\Route;
20+
21+
class RouterControllerTest extends WebTestCase
22+
{
23+
public function testFalseNegativeTrace()
24+
{
25+
$path = '/foo/bar:123/baz';
26+
27+
$kernel = new WebProfilerBundleKernel();
28+
$client = new KernelBrowser($kernel);
29+
$client->disableReboot();
30+
$client->getKernel()->boot();
31+
32+
/** @var Router $router */
33+
$router = $client->getContainer()->get('router');
34+
$router->getRouteCollection()->add('route1', new Route($path));
35+
36+
$client->request('GET', $path);
37+
38+
$crawler = $client->request('GET', '/_profiler/latest?panel=router&type=request');
39+
40+
$matchedRouteCell = $crawler
41+
->filter('#router-logs .status-success td')
42+
->reduce(function (Crawler $td) use ($path): bool {
43+
return $td->text() === $path;
44+
});
45+
46+
$this->assertSame(1, $matchedRouteCell->count());
47+
}
48+
}

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,11 @@ function (ExpressionLanguage $el) {
460460
],
461461
];
462462
}
463+
464+
public function testParseAlreadyParsedExpressionReturnsSameObject()
465+
{
466+
$el = new ExpressionLanguage();
467+
$parsed = $el->parse('1 + 1', []);
468+
$this->assertSame($parsed, $el->parse($parsed, []));
469+
}
463470
}

src/Symfony/Component/ExpressionLanguage/Tests/Node/BinaryNodeTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,26 @@ public function testCompileMatchesWithInvalidRegexpAsExpression()
218218
eval('$regexp = "this is not a regexp"; '.$compiler->getSource().';');
219219
}
220220

221+
public function testDivisionByZero()
222+
{
223+
$node = new BinaryNode('/', new ConstantNode(1), new ConstantNode(0));
224+
225+
$this->expectException(\DivisionByZeroError::class);
226+
$this->expectExceptionMessage('Division by zero.');
227+
228+
$node->evaluate([], []);
229+
}
230+
231+
public function testModuloByZero()
232+
{
233+
$node = new BinaryNode('%', new ConstantNode(1), new ConstantNode(0));
234+
235+
$this->expectException(\DivisionByZeroError::class);
236+
$this->expectExceptionMessage('Modulo by zero.');
237+
238+
$node->evaluate([], []);
239+
}
240+
221241
/**
222242
* @group legacy
223243
*/

src/Symfony/Component/ExpressionLanguage/Tests/Node/NodeTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\ExpressionLanguage\Tests\Node;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\ExpressionLanguage\Compiler;
1516
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
1617
use Symfony\Component\ExpressionLanguage\Node\Node;
1718

@@ -38,4 +39,33 @@ public function testSerialization()
3839

3940
$this->assertEquals($node, $unserializedNode);
4041
}
42+
43+
public function testCompileActuallyCompilesAllNodes()
44+
{
45+
$nodes = [];
46+
foreach (range(1, 10) as $ignored) {
47+
$node = $this->createMock(Node::class);
48+
$node->expects($this->once())->method('compile');
49+
50+
$nodes[] = $node;
51+
}
52+
53+
$node = new Node($nodes);
54+
$node->compile($this->createMock(Compiler::class));
55+
}
56+
57+
public function testEvaluateActuallyEvaluatesAllNodes()
58+
{
59+
$nodes = [];
60+
foreach (range(1, 3) as $i) {
61+
$node = $this->createMock(Node::class);
62+
$node->expects($this->once())->method('evaluate')
63+
->willReturn($i);
64+
65+
$nodes[] = $node;
66+
}
67+
68+
$node = new Node($nodes);
69+
$this->assertSame([1, 2, 3], $node->evaluate([], []));
70+
}
4171
}

src/Symfony/Component/ExpressionLanguage/Tests/ParserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ public function testParseWithZeroInNames()
3737
$parser->parse($lexer->tokenize('foo'), [0]);
3838
}
3939

40+
public function testParsePrimaryExpressionWithUnknownFunctionThrows()
41+
{
42+
$parser = new Parser([]);
43+
$stream = (new Lexer())->tokenize('foo()');
44+
45+
$this->expectException(SyntaxError::class);
46+
$this->expectExceptionMessage('The function "foo" does not exist around position 1 for expression `foo()`.');
47+
48+
$parser->parse($stream);
49+
}
50+
4051
/**
4152
* @dataProvider getParseData
4253
*/

src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ public function current(): SplFileInfo
6363
$subPathname .= $this->directorySeparator;
6464
}
6565
$subPathname .= $this->getFilename();
66+
$basePath = $this->rootPath;
6667

67-
if ('/' !== $basePath = $this->rootPath) {
68+
if ('/' !== $basePath && !str_ends_with($basePath, $this->directorySeparator) && !str_ends_with($basePath, '/')) {
6869
$basePath .= $this->directorySeparator;
6970
}
7071

src/Symfony/Component/Finder/Tests/Iterator/RecursiveDirectoryIteratorTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,31 @@ public function testSeekOnFtp()
5555

5656
$this->assertEquals($contains, $actual);
5757
}
58+
59+
public function testTrailingDirectorySeparatorIsStripped()
60+
{
61+
$fixturesDirectory = __DIR__ . '/../Fixtures/';
62+
$actual = [];
63+
64+
foreach (new RecursiveDirectoryIterator($fixturesDirectory, RecursiveDirectoryIterator::SKIP_DOTS) as $file) {
65+
$actual[] = $file->getPathname();
66+
}
67+
68+
sort($actual);
69+
70+
$expected = [
71+
$fixturesDirectory.'.dot',
72+
$fixturesDirectory.'A',
73+
$fixturesDirectory.'copy',
74+
$fixturesDirectory.'dolor.txt',
75+
$fixturesDirectory.'gitignore',
76+
$fixturesDirectory.'ipsum.txt',
77+
$fixturesDirectory.'lorem.txt',
78+
$fixturesDirectory.'one',
79+
$fixturesDirectory.'r+e.gex[c]a(r)s',
80+
$fixturesDirectory.'with space',
81+
];
82+
83+
$this->assertEquals($expected, $actual);
84+
}
5885
}

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function reverseTransform(mixed $value): int|float|null
106106
$value = str_replace(',', $decSep, $value);
107107
}
108108

109-
if (str_contains($value, $decSep)) {
109+
//If the value is in exponential notation with a negative exponent, we end up with a float value too
110+
if (str_contains($value, $decSep) || false !== stripos($value, 'e-')) {
110111
$type = \NumberFormatter::TYPE_DOUBLE;
111112
} else {
112113
$type = \PHP_INT_SIZE === 8

0 commit comments

Comments
 (0)