Skip to content

Commit bc626d5

Browse files
Merge branch '4.4' into 5.4
* 4.4: [HttpKernel] Fix empty request stack when terminating with exception [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger s/annd/and s/gargage/garbage [Console] Fix error output on windows cli Reserve keys when using numeric ones add missing Azerbaijani translations fix few typos/inconsistencies in latvian translations fix: use message object from event
2 parents d50fbf6 + dffff8e commit bc626d5

File tree

14 files changed

+120
-22
lines changed

14 files changed

+120
-22
lines changed

src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ protected function doInvalidate(array $tagIds): bool
208208
// and removes the linked items. When the set is still not empty after
209209
// the scan, it means we're in cluster mode and that the linked items
210210
// are on other nodes: we move the links to a temporary set and we
211-
// gargage collect that set from the client side.
211+
// garbage collect that set from the client side.
212212

213213
$lua = <<<'EOLUA'
214214
redis.replicate_commands()

src/Symfony/Component/Cache/Tests/Adapter/AdapterTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@ public function testNullByteInKey()
341341

342342
$this->assertSame(123, $cache->getItem("a\0b")->get());
343343
}
344+
345+
public function testNumericKeysWorkAfterMemoryLeakPrevention()
346+
{
347+
$cache = $this->createCachePool(0, __FUNCTION__);
348+
349+
for ($i = 0; $i < 1001; ++$i) {
350+
$cacheItem = $cache->getItem((string) $i);
351+
$cacheItem->set('value-'.$i);
352+
$cache->save($cacheItem);
353+
}
354+
355+
$this->assertEquals('value-50', $cache->getItem((string) 50)->get());
356+
}
344357
}
345358

346359
class NotUnserializable

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private function getId($key)
394394
$this->ids[$key] = $key;
395395

396396
if (\count($this->ids) > 1000) {
397-
array_splice($this->ids, 0, 500); // stop memory leak if there are many keys
397+
$this->ids = \array_slice($this->ids, 500, null, true); // stop memory leak if there are many keys
398398
}
399399

400400
if (null === $this->maxIdLength) {

src/Symfony/Component/Console/Application.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
276276
$alternative = $alternatives[0];
277277

278278
$style = new SymfonyStyle($input, $output);
279-
$style->block(sprintf("\nCommand \"%s\" is not defined.\n", $name), null, 'error');
279+
$style->block(sprintf('Command "%s" is not defined.', $name), null, 'error', ' ', true);
280280
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
281281
if (null !== $this->dispatcher) {
282282
$event = new ConsoleErrorEvent($input, $output, $e);
@@ -933,11 +933,21 @@ protected function configureIO(InputInterface $input, OutputInterface $output)
933933
}
934934

935935
switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
936-
case -1: $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); break;
937-
case 1: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); break;
938-
case 2: $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); break;
939-
case 3: $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); break;
940-
default: $shellVerbosity = 0; break;
936+
case -1:
937+
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
938+
break;
939+
case 1:
940+
$output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
941+
break;
942+
case 2:
943+
$output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
944+
break;
945+
case 3:
946+
$output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
947+
break;
948+
default:
949+
$shellVerbosity = 0;
950+
break;
941951
}
942952

943953
if (true === $input->hasParameterOption(['--quiet', '-q'], true)) {

src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* A list of choices with arbitrary data types.
1616
*
1717
* The user of this class is responsible for assigning string values to the
18-
* choices annd for their uniqueness.
18+
* choices and for their uniqueness.
1919
* Both the choices and their values are passed to the constructor.
2020
* Each choice must have a corresponding value (with the same key) in
2121
* the values array.

src/Symfony/Component/Form/Resources/translations/validators.lv.xlf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
</trans-unit>
133133
<trans-unit id="128">
134134
<source>Please enter a valid week.</source>
135-
<target>Lūdzu, ievadiet derīgu nedeļu.</target>
135+
<target>Lūdzu, ievadiet derīgu nedēļu.</target>
136136
</trans-unit>
137137
</body>
138138
</file>

src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,17 @@ public function terminateWithException(\Throwable $exception, Request $request =
106106
throw $exception;
107107
}
108108

109-
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
109+
if ($pop = $request !== $this->requestStack->getMainRequest()) {
110+
$this->requestStack->push($request);
111+
}
112+
113+
try {
114+
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
115+
} finally {
116+
if ($pop) {
117+
$this->requestStack->pop();
118+
}
119+
}
110120

111121
$response->sendHeaders();
112122
$response->sendContent();

src/Symfony/Component/HttpKernel/Log/Logger.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ public function __construct(string $minLevel = null, $output = null, callable $f
4949

5050
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
5151
switch ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'])) {
52-
case -1: $minLevel = LogLevel::ERROR; break;
53-
case 1: $minLevel = LogLevel::NOTICE; break;
54-
case 2: $minLevel = LogLevel::INFO; break;
55-
case 3: $minLevel = LogLevel::DEBUG; break;
52+
case -1: $minLevel = LogLevel::ERROR;
53+
break;
54+
case 1: $minLevel = LogLevel::NOTICE;
55+
break;
56+
case 2: $minLevel = LogLevel::INFO;
57+
break;
58+
case 3: $minLevel = LogLevel::DEBUG;
59+
break;
5660
}
5761
}
5862
}
@@ -85,7 +89,7 @@ public function log($level, $message, array $context = [])
8589

8690
$formatter = $this->formatter;
8791
if ($this->handle) {
88-
@fwrite($this->handle, $formatter($level, $message, $context));
92+
@fwrite($this->handle, $formatter($level, $message, $context).\PHP_EOL);
8993
} else {
9094
error_log($formatter($level, $message, $context, false));
9195
}
@@ -110,7 +114,7 @@ private function format(string $level, string $message, array $context, bool $pr
110114
$message = strtr($message, $replacements);
111115
}
112116

113-
$log = sprintf('[%s] %s', $level, $message).\PHP_EOL;
117+
$log = sprintf('[%s] %s', $level, $message);
114118
if ($prefixDate) {
115119
$log = date(\DateTime::RFC3339).' '.$log;
116120
}

src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,22 @@ public function testTerminate()
341341
$this->assertEquals($response, $capturedResponse);
342342
}
343343

344+
public function testTerminateWithException()
345+
{
346+
$dispatcher = new EventDispatcher();
347+
$requestStack = new RequestStack();
348+
$kernel = $this->getHttpKernel($dispatcher, null, $requestStack);
349+
350+
$dispatcher->addListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) use (&$capturedRequest, $requestStack) {
351+
$capturedRequest = $requestStack->getCurrentRequest();
352+
$event->setResponse(new Response());
353+
});
354+
355+
$kernel->terminateWithException(new \Exception('boo'), $request = Request::create('/'));
356+
$this->assertSame($request, $capturedRequest);
357+
$this->assertNull($requestStack->getCurrentRequest());
358+
}
359+
344360
public function testVerifyRequestStackPushPopDuringHandle()
345361
{
346362
$request = new Request();

src/Symfony/Component/HttpKernel/Tests/Log/LoggerTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function tearDown(): void
4848
public static function assertLogsMatch(array $expected, array $given)
4949
{
5050
foreach ($given as $k => $line) {
51-
self::assertThat(1 === preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[\+-][0-9]{2}:[0-9]{2} '.preg_quote($expected[$k]).'/', $line), self::isTrue(), "\"$line\" do not match expected pattern \"$expected[$k]\"");
51+
self::assertSame(1, preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[\+-][0-9]{2}:[0-9]{2} '.preg_quote($expected[$k]).'/', $line), "\"$line\" do not match expected pattern \"$expected[$k]\"");
5252
}
5353
}
5454

@@ -186,7 +186,7 @@ public function testContextExceptionKeyCanBeExceptionOrOtherValues()
186186
public function testFormatter()
187187
{
188188
$this->logger = new Logger(LogLevel::DEBUG, $this->tmpFile, function ($level, $message, $context) {
189-
return json_encode(['level' => $level, 'message' => $message, 'context' => $context]).\PHP_EOL;
189+
return json_encode(['level' => $level, 'message' => $message, 'context' => $context]);
190190
});
191191

192192
$this->logger->error('An error', ['foo' => 'bar']);
@@ -196,6 +196,26 @@ public function testFormatter()
196196
'{"level":"warning","message":"A warning","context":{"baz":"bar"}}',
197197
], $this->getLogs());
198198
}
199+
200+
public function testLogsWithoutOutput()
201+
{
202+
$oldErrorLog = ini_set('error_log', $this->tmpFile);
203+
204+
$logger = new Logger();
205+
$logger->error('test');
206+
$logger->critical('test');
207+
208+
$expected = [
209+
'[error] test',
210+
'[critical] test',
211+
];
212+
213+
foreach ($this->getLogs() as $k => $line) {
214+
$this->assertSame(1, preg_match('/\[[\w\/\-: ]+\] '.preg_quote($expected[$k]).'/', $line), "\"$line\" do not match expected pattern \"$expected[$k]\"");
215+
}
216+
217+
ini_set('error_log', $oldErrorLog);
218+
}
199219
}
200220

201221
class DummyTest

src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
6565
$event = new MessageEvent($message, $envelope, (string) $this);
6666
$this->dispatcher->dispatch($event);
6767
$envelope = $event->getEnvelope();
68+
$message = $event->getMessage();
6869
}
6970

7071
$message = new SentMessage($message, $envelope);

src/Symfony/Component/Security/Core/Resources/translations/security.az.xlf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070
<source>Invalid or expired login link.</source>
7171
<target>Yanlış və ya müddəti keçmiş giriş keçidi.</target>
7272
</trans-unit>
73+
<trans-unit id="19">
74+
<source>Too many failed login attempts, please try again in %minutes% minute.</source>
75+
<target>Həddindən artıq uğursuz giriş cəhdi, lütfən %minutes% dəqiqə ərzində yenidən yoxlayın.</target>
76+
</trans-unit>
77+
<trans-unit id="20">
78+
<source>Too many failed login attempts, please try again in %minutes% minutes.</source>
79+
<target>Həddindən artıq uğursuz giriş cəhdi, lütfən %minutes% dəqiqə ərzində yenidən yoxlayın.</target>
80+
</trans-unit>
7381
</body>
7482
</file>
7583
</xliff>

src/Symfony/Component/Security/Core/Resources/translations/security.lv.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</trans-unit>
2525
<trans-unit id="6">
2626
<source>Not privileged to request the resource.</source>
27-
<target>Nav tiesību ši resursa izsaukšanai.</target>
27+
<target>Nav tiesību šī resursa izsaukšanai.</target>
2828
</trans-unit>
2929
<trans-unit id="7">
3030
<source>Invalid CSRF token.</source>
@@ -64,11 +64,11 @@
6464
</trans-unit>
6565
<trans-unit id="17">
6666
<source>Too many failed login attempts, please try again later.</source>
67-
<target>Pārāk daudz atteiktu ieejas mēģinājumu, lūdzu, mēģiniet vēlreiz vēlāk.</target>
67+
<target>Pārāk daudz atteiktu autentifikācijas mēģinājumu, lūdzu, mēģiniet vēlreiz vēlāk.</target>
6868
</trans-unit>
6969
<trans-unit id="18">
7070
<source>Invalid or expired login link.</source>
71-
<target>Ieejas saite ir nederīga vai arī tai ir beidzies derīguma termiņš.</target>
71+
<target>Autentifikācijas saite ir nederīga vai arī tai ir beidzies derīguma termiņš.</target>
7272
</trans-unit>
7373
<trans-unit id="19">
7474
<source>Too many failed login attempts, please try again in %minutes% minute.</source>

src/Symfony/Component/Validator/Resources/translations/validators.az.xlf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,22 @@
386386
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387387
<target>Bu dəyər doğru bir Qiymətli Kağızın Beynəlxalq İdentifikasiya Kodu (ISIN) deyil.</target>
388388
</trans-unit>
389+
<trans-unit id="100">
390+
<source>This value should be a valid expression.</source>
391+
<target>Bu dəyər etibarlı ifadə olmalıdır.</target>
392+
</trans-unit>
393+
<trans-unit id="101">
394+
<source>This value is not a valid CSS color.</source>
395+
<target>Bu dəyər etibarlı CSS rəngi deyil.</target>
396+
</trans-unit>
397+
<trans-unit id="102">
398+
<source>This value is not a valid CIDR notation.</source>
399+
<target>Bu dəyər etibarlı CIDR notasiyası deyil.</target>
400+
</trans-unit>
401+
<trans-unit id="103">
402+
<source>The value of the netmask should be between {{ min }} and {{ max }}.</source>
403+
<target>Şəbəkə maskasının dəyəri {{ min }} və {{ max }} arasında olmalıdır.</target>
404+
</trans-unit>
389405
</body>
390406
</file>
391407
</xliff>

0 commit comments

Comments
 (0)