8000 Merge branch '4.3' into 4.4 · Koc/symfony@4acef47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4acef47

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Form][Validator][Intl] Fix tests [Messenger] return empty envelopes when RetryableException occurs [Validator] Accept underscores in the URL validator as the URL will resolve correctly [Translation] Collect original locale in case of fallback translation Fix toolbar load when GET params are present in "_wdt" route
2 parents 161975d + 7bb421b commit 4acef47

File tree

11 files changed

+64
-18
lines changed

11 files changed

+64
-18
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
{% set text %}
1515
<div class="sf-toolbar-info-piece">
16-
<b>Locale</b>
16+
<b>Default locale</b>
1717
<span class="sf-toolbar-status">
1818
{{ collector.locale|default('-') }}
1919
</span>
@@ -61,7 +61,7 @@
6161
<div class="metrics">
6262
<div class="metric">
6363
<span class="value">{{ collector.locale|default('-') }}</span>
64-
<span class="label">Locale</span>
64+
<span class="label">Default locale</span>
6565
</div>
6666
<div class="metric">
6767
<span class="value">{{ collector.fallbackLocales|join(', ')|default('-') }}</span>
@@ -126,7 +126,7 @@
126126
</div>
127127
{% else %}
128128
{% block fallback_messages %}
129-
{{ helper.render_table(messages_fallback) }}
129+
{{ helper.render_table(messages_fallback, true) }}
130130
{% endblock %}
131131
{% endif %}
132132
</div>
@@ -162,11 +162,14 @@
162162

163163
{% endblock %}
164164

165-
{% macro render_table(messages) %}
165+
{% macro render_table(messages, is_fallback) %}
166166
<table data-filters>
167167
<thead>
168168
<tr>
169169
<th data-filter="locale">Locale</th>
170+
{% if is_fallback %}
171+
<th>Fallback locale</th>
172+
{% endif %}
170173
<th data-filter="domain">Domain</th>
171174
<th>Times used</th>
172175
<th>Message ID</th>
@@ -177,6 +180,9 @@
177180
{% for message in messages %}
178181
<tr data-filter-locale="{{ message.locale }}" data-filter-domain="{{ message.domain }}">
179182
<td class="font-normal text-small nowrap">{{ message.locale }}</td>
183+
{% if is_fallback %}
184+
<td class="font-normal text-small nowrap">{{ message.fallbackLocale|default('-') }}</td>
185+
{% endif %}
180186
<td class="font-normal text-small text-bold nowrap">{{ message.domain }}</td>
181187
<td class="font-normal text-small nowrap">{{ message.count }}</td>
182188
<td>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@
429429
newToken = (newToken || token);
430430
this.load(
431431
'sfwdt' + token,
432-
'{{ path("_wdt", { "token": "xxxxxx" }) }}'.replace(/xxxxxx/, newToken),
432+
'{{ path("_wdt", { "token": "xxxxxx" })|escape('js') }}'.replace(/xxxxxx/, newToken),
433433
function(xhr, el) {
434434
435435
/* Evaluate in global scope scripts embedded inside the toolbar */
@@ -532,7 +532,7 @@
532532
sfwdt.innerHTML = '\
533533
<div class="sf-toolbarreset">\
534534
<div class="sf-toolbar-icon"><svg width="26" height="28" xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" viewBox="0 0 26 28" enable-background="new 0 0 26 28" xml:space="preserve"><path fill="#FFFFFF" d="M13 0C5.8 0 0 5.8 0 13c0 7.2 5.8 13 13 13c7.2 0 13-5.8 13-13C26 5.8 20.2 0 13 0z M20 7.5 c-0.6 0-1-0.3-1-0.9c0-0.2 0-0.4 0.2-0.6c0.1-0.3 0.2-0.3 0.2-0.4c0-0.3-0.5-0.4-0.7-0.4c-2 0.1-2.5 2.7-2.9 4.8l-0.2 1.1 c1.1 0.2 1.9 0 2.4-0.3c0.6-0.4-0.2-0.8-0.1-1.3C18 9.2 18.4 9 18.7 8.9c0.5 0 0.8 0.5 0.8 1c0 0.8-1.1 2-3.3 1.9 c-0.3 0-0.5 0-0.7-0.1L15 14.1c-0.4 1.7-0.9 4.1-2.6 6.2c-1.5 1.8-3.1 2.1-3.8 2.1c-1.3 0-2.1-0.6-2.2-1.6c0-0.9 0.8-1.4 1.3-1.4 c0.7 0 1.2 0.5 1.2 1.1c0 0.5-0.2 0.6-0.4 0.7c-0.1 0.1-0.3 0.2-0.3 0.4c0 0.1 0.1 0.3 0.4 0.3c0.5 0 0.9-0.3 1.2-0.5 c1.3-1 1.7-2.9 2.4-6.2l0.1-0.8c0.2-1.1 0.5-2.3 0.8-3.5c-0.9-0.7-1.4-1.5-2.6-1.8c-0.8-0.2-1.3 0-1.7 0.4C8.4 10 8.6 10.7 9 11.1 l0.7 0.7c0.8 0.9 1.3 1.7 1.1 2.7c-0.3 1.6-2.1 2.8-4.3 2.1c-1.9-0.6-2.2-1.9-2-2.7c0.2-0.6 0.7-0.8 1.2-0.6 c0.5 0.2 0.7 0.8 0.6 1.3c0 0.1 0 0.1-0.1 0.3C6 15 5.9 15.2 5.9 15.3c-0.1 0.4 0.4 0.7 0.8 0.8c0.8 0.3 1.7-0.2 1.9-0.9 c0.2-0.6-0.2-1.1-0.4-1.2l-0.8-0.9c-0.4-0.4-1.2-1.5-0.8-2.8c0.2-0.5 0.5-1 0.9-1.4c1-0.7 2-0.8 3-0.6c1.3 0.4 1.9 1.2 2.8 1.9 c0.5-1.3 1.1-2.6 2-3.8c0.9-1 2-1.7 3.3-1.8C20 4.8 21 5.4 21 6.3C21 6.7 20.8 7.5 20 7.5z"/></svg></div>\
535-
An error occurred while loading the web debug toolbar. <a href="{{ path("_profiler_home") }}' + newToken + '>Open the web profiler.</a>\
535+
An error occurred while loading the web debug toolbar. <a href="{{ path("_profiler_home")|escape('js') }}' + newToken + '>Open the web profiler.</a>\
536536
</div>\
537537
';
538538
sfwdt.setAttribute('class', 'sf-toolbar sf-error-toolbar');

src/Symfony/Component/Form/Tests/Extension/Core/Type/LanguageTypeTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public function testCountriesAreSelectable()
3232
->createView()->vars['choices'];
3333

3434
$this->assertContainsEquals(new ChoiceView('en', 'en', 'English'), $choices);
35-
$this->assertContainsEquals(new ChoiceView('en_GB', 'en_GB', 'British English'), $choices);
36-
$this->assertContainsEquals(new ChoiceView('en_US', 'en_US', 'American English'), $choices);
3735
$this->assertContainsEquals(new ChoiceView('fr', 'fr', 'French'), $choices);
3836
$this->assertContainsEquals(new ChoiceView('my', 'my', 'Burmese'), $choices);
3937
}
@@ -51,7 +49,6 @@ public function testChoiceTranslationLocaleOption()
5149

5250
// Don't check objects for identity
5351
$this->assertContainsEquals(new ChoiceView('en', 'en', 'англійська'), $choices);
54-
$this->assertContainsEquals(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices);
5552
$this->assertContainsEquals(new ChoiceView('fr', 'fr', 'французька'), $choices);
5653
$this->assertContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices);
5754
}

src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineReceiverTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
1313

14+
use Doctrine\DBAL\Driver\PDOException;
15+
use Doctrine\DBAL\Exception\DeadlockException;
1416
use PHPUnit\Framework\TestCase;
1517
use Symfony\Component\Messenger\Envelope;
1618
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
19+
use Symfony\Component\Messenger\Exception\TransportException;
1720
use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp;
1821
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
1922
use Symfony\Component\Messenger\Transport\Doctrine\Connection;
@@ -68,6 +71,26 @@ public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException()
6871
$receiver->get();
6972
}
7073

74+
public function testOccursRetryableExceptionFromConnection()
75+
{
76+
$serializer = $this->createSerializer();
77+
$connection = $this->createMock(Connection::class);
78+
$driverException = new PDOException(new \PDOException('Deadlock', 40001));
79+
$connection->method('get')->willThrowException(new DeadlockException('Deadlock', $driverException));
80+
$receiver = new DoctrineReceiver($connection, $serializer);
81+
$this->assertSame([], $receiver->get());
82+
$this->assertSame([], $receiver->get());
83+
try {
84+
$receiver->get();
85+
} catch (TransportException $exception) {
86+
// skip, and retry
87+
}
88+
$this->assertSame([], $receiver->get());
89+
$this->assertSame([], $receiver->get());
90+
$this->expectException(TransportException::class);
91+
$receiver->get();
92+
}
93+
7194
public function testAll()
7295
{
7396
$serializer = $this->createSerializer();

src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Transport\Doctrine;
1313

1414
use Doctrine\DBAL\DBALException;
15+
use Doctrine\DBAL\Exception\RetryableException;
1516
use Symfony\Component\Messenger\Envelope;
1617
use Symfony\Component\Messenger\Exception\LogicException;
1718
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
@@ -28,6 +29,8 @@
2829
*/
2930
class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface, ListableReceiverInterface
3031
{
32+
private const MAX_RETRIES = 3;
33+
private $retryingSafetyCounter = 0;
3134
private $connection;
3235
private $serializer;
3336

@@ -44,6 +47,17 @@ public function get(): iterable
4447
{
4548
try {
4649
$doctrineEnvelope = $this->connection->get();
50+
$this->retryingSafetyCounter = 0; // reset counter
51+
} catch (RetryableException $exception) {
52+
// Do nothing when RetryableException occurs less than "MAX_RETRIES"
53+
// as it will likely be resolved on the next call to get()
54+
// Problem with concurrent consumers and database deadlocks
55+
if (++$this->retryingSafetyCounter >= self::MAX_RETRIES) {
56+
$this->retryingSafetyCounter = 0; // reset counter
57+
throw new TransportException($exception->getMessage(), 0, $exception);
58+
}
59+
60+
return [];
4761
} catch (DBALException $exception) {
4862
throw new TransportException($exception->getMessage(), 0, $exception);
4963
}

src/Symfony/Component/Messenger/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"psr/log": "~1.0"
2121
},
2222
"require-dev": {
23-
"doctrine/dbal": "^2.5",
23+
"doctrine/dbal": "^2.6",
2424
"psr/cache": "~1.0",
2525
"doctrine/persistence": "~1.0",
2626
"symfony/console": "^3.4|^4.0|^5.0",

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ private function collectMessage(?string $locale, ?string $domain, ?string $id, s
150150
$id = (string) $id;
151151
$catalogue = $this->translator->getCatalogue($locale);
152152
$locale = $catalogue->getLocale();
153+
$fallbackLocale = null;
153154
if ($catalogue->defines($id, $domain)) {
154155
$state = self::MESSAGE_DEFINED;
155156
} elseif ($catalogue->has($id, $domain)) {
@@ -158,10 +159,9 @@ private function collectMessage(?string $locale, ?string $domain, ?string $id, s
158159
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
159160
while ($fallbackCatalogue) {
160161
if ($fallbackCatalogue->defines($id, $domain)) {
161-
$locale = $fallbackCatalogue->getLocale();
162+
$fallbackLocale = $fallbackCatalogue->getLocale();
162163
break;
163164
}
164-
165165
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
166166
}
167167
} else {
@@ -170,6 +170,7 @@ private function collectMessage(?string $locale, ?string $domain, ?string $id, s
170170

171171
$this->messages[] = [
172172
'locale' => $locale,
173+
'fallbackLocale' => $fallbackLocale,
173174
'domain' => $domain,
174175
'id' => $id,
175176
'translation' => $translation,

src/Symfony/Component/Translation/Tests/DataCollectorTranslatorTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testCollectMessages()
3434
'id' => 'foo',
3535
'translation' => 'foo (en)',
3636
'locale' => 'en',
37+
'fallbackLocale' => null,
3738
'domain' => 'messages',
3839
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
3940
'parameters' => [],
@@ -42,7 +43,8 @@ public function testCollectMessages()
4243
$expectedMessages[] = [
4344
'id' => 'bar',
4445
'translation' => 'bar (fr)',
45-
'locale' => 'fr',
46+
'locale' => 'en',
47+
'fallbackLocale' => 'fr',
4648
'domain' => 'messages',
4749
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
4850
'parameters' => [],
@@ -52,6 +54,7 @@ public function testCollectMessages()
5254
'id' => 'choice',
5355
'translation' => 'choice',
5456
'locale' => 'en',
57+
'fallbackLocale' => null,
5558
'domain' => 'messages',
5659
'state' => DataCollectorTranslator::MESSAGE_MISSING,
5760
'parameters' => ['%count%' => 0],
@@ -60,7 +63,8 @@ public function testCollectMessages()
6063
$expectedMessages[] = [
6164
'id' => 'bar_ru',
6265
'translation' => 'bar (ru)',
63-
'locale' => 'ru',
66+
'locale' => 'en',
67+
'fallbackLocale' => 'ru',
6468
'domain' => 'messages',
6569
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
6670
'parameters' => [],
@@ -69,7 +73,8 @@ public function testCollectMessages()
6973
$expectedMessages[] = [
7074
'id' => 'bar_ru',
7175
'translation' => 'bar (ru)',
72-
'locale' => 'ru',
76+
'locale' => 'en',
77+
'fal 10000 lbackLocale' => 'ru',
7378
'domain' => 'messages',
7479
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
7580
'parameters' => ['foo' => 'bar'],

src/Symfony/Component/Validator/Constraints/UrlValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class UrlValidator extends ConstraintValidator
2626
(%s):// # protocol
2727
(([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth
2828
(
29-
([\pL\pN\pS\-\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
29+
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
3030
| # or
3131
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
3232
| # or

src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public function getValidLanguages()
7373
{
7474
return [
7575
['en'],
76-
['en_US'],
7776
['my'],
7877
];
7978
}

src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function getValidUrls()
106106
['http://www.example.museum'],
107107
['https://example.com/'],
108108
['https://example.com:80/'],
109+
['http://examp_le.com'],
110+
['http://www.sub_domain.examp_le.com'],
109111
['http://www.example.coop/'],
110112
['http://www.test-example.com/'],
111113
['http://www.symfony.com/'],
@@ -239,7 +241,6 @@ public function getInvalidUrls()
239241
['://example.com'],
240242
['http ://example.com'],
241243
['http:/example.com'],
242-
['http://examp_le.com'],
243244
['http://example.com::aa'],
244245
['http://example.com:aa'],
245246
['ftp://example.fr'],

0 commit comments

Comments
 (0)
0