8000 Merge branch '4.2' · symfony/symfony@32aa969 · GitHub
[go: up one dir, main page]

Skip to content

Commit 32aa969

Browse files
Merge branch '4.2'
* 4.2: [Routing] dont redirect routes with greedy trailing vars with no explicit slash skip native serialize among child and parent serializable objects [Routing] backport tests from 4.1 [MonologBridge] Remove unused local variable Remove unreachable code Add PackageNameTest to ConfigurationTest also add in the changelog the corresponding entry to this PR Support use of hyphen in asset package name Fix format strings for deprecation notices Remove a harmless duplicate array key from VarDumper [VarDumper] Fixed search bar Remove gendered pronouns Replace gender by eye color in tests [Security] dont do nested calls to serialize()
2 parents be5d85e + adbdec8 commit 32aa969

36 files changed

+203
-117
lines changed

src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public function isHandlerActivated(array $record)
6060
continue;
6161
}
6262

63-
$urlBlacklist = null;
6463
if (\count($exclusion['urls'])) {
6564
return !preg_match('{('.implode('|', $exclusion['urls']).')}i', $request->getPathInfo());
6665
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
648648
->fixXmlConfig('package')
649649
->children()
650650
->arrayNode('packages')
651+
->normalizeKeys(false)
651652
->useAttributeAsKey('name')
652653
->prototype('array')
653654
->fixXmlConfig('base_url')

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/TranslatorHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function trans($id, array $parameters = [], $domain = 'messages', $locale
5858
*/
5959
public function transChoice($id, $number, array $parameters = [], $domain = 'messages', $locale = null)
6060
{
61-
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%count%" parameter.', __METHOD__), E_USER_DEPRECATED);
61+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%%count%%" parameter.', __METHOD__), E_USER_DEPRECATED);
6262

6363
if (null === $this->translator) {
6464
return $this->doTrans($id, ['%count%' => $number] + $parameters, $domain, $locale);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,35 @@ public function testAssetsCanBeEnabled()
101101
$this->assertEquals($defaultConfig, $config['assets']);
102102
}
103103

104+
/**
105+
* @dataProvider provideValidAssetsPackageNameConfigurationTests
106+
*/
107+
public function testValidAssetsPackageNameConfiguration($packageName)
108+
{
109+
$processor = new Processor();
110+
$configuration = new Configuration(true);
111+
$config = $processor->processConfiguration($configuration, [
112+
[
113+
'assets' => [
114+
'packages' => [
115+
$packageName => [],
116+
],
117+
],
118+
],
119+
]);
120+
121+
$this->assertArrayHasKey($packageName, $config['assets']['packages']);
122+
}
123+
124+
public function provideValidAssetsPackageNameConfigurationTests()
125+
{
126+
return [
127+
['foobar'],
128+
['foo-bar'],
129+
['foo_bar'],
130+
];
131+
}
132+
104133
/**
105134
* @dataProvider provideInvalidAssetConfigurationTests
106135
*/

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Serialization/Author.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class Author
66
{
7-
public $gender;
7+
public $eyeColor;
88
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Serialization/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class Person
66
{
7-
public $gender;
7+
public $eyeColor;
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serialization\Author:
22
attributes:
3-
gender:
3+
eyeColor:
44
groups: ['group1', 'group2']

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Serialization/Resources/person.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
66
>
77
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serialization\Person">
8-
<attribute name="gender">
8+
<attribute name="eyeColor">
99
<group>group1</group>
1010
<group>group2</group>
1111
</attribute>

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Author.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class Author
66
{
7-
public $gender;
7+
public $eyeColor;
88
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Person.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class Person
66
{
7-
public $gender;
7+
public $eyeColor;
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Author:
22
properties:
3-
gender:
4-
- Choice: { choices: [male, female, other], message: Choose a valid gender. }
3+
eyeColor:
4+
- Choice: { choices: [brown, green, blue], message: Choose a valid eye color. }

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Resources/person.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
55

66
<class name="Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Person">
7-
<property name="gender">
7+
<property name="eyeColor">
88
<constraint name="Choice">
99
<option name="choices">
10-
<value>male</value>
11-
<value>female</value>
12-
<value>other</value>
10+
<value>brown</value>
11+
<value>green</value>
12+
<value>blue</value>
1313
</option>
14-
<option name="message">Choose a valid gender.</option>
14+
<option name="message">Choose a valid eye color.</option>
1515
</constraint>
1616
</property>
1717
</class>

src/Symfony/Component/Form/FormRenderer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
163163
// to implement a custom "choice_widget" block (no matter in which theme),
164164
// or to fallback to the block of the parent type, which would be
165165
// "form_widget" in this example (again, no matter in which theme).
166-
// If the designer wants to explicitly fallback to "form_widget" in his
167-
// custom "choice_widget", for example because he only wants to wrap
168-
// a <div> around the original implementation, he can simply call the
166+
// If the designer wants to explicitly fallback to "form_widget" in their
167+
// custom "choice_widget", for example because they only want to wrap
168+
// a <div> around the original implementation, they can simply call the
169169
// widget() function again to render the block for the parent type.
170170
//
171171
// The second kind is implemented in the following blocks.

src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public function testFormEndWithRest()
470470
// Insert the start tag, the end tag should be rendered by the helper
471471
// Unfortunately this is not valid HTML, because the surrounding table
472472
// tag is missing. If someone renders a form with table layout
473-
// manually, she should call form_rest() explicitly within the <table>
473+
// manually, they should call form_rest() explicitly within the <table>
474474
// tag.
475475
$this->assertMatchesXpath('<form>'.$html,
476476
'/form

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,14 +783,14 @@ public function getQueryStringNormalizationData()
783783

784784
// GET parameters, that are submitted from a HTML form, encode spaces as "+" by default (as defined in enctype application/x-www-form-urlencoded).
785785
// PHP also converts "+" to spaces when filling the global _GET or when using the function parse_str.
786-
['him=John%20Doe&her=Jane+Doe', 'her=Jane%20Doe&him=John%20Doe', 'normalizes spaces in both encodings "%20" and "+"'],
786+
['baz=Foo%20Baz&bar=Foo+Bar', 'bar=Foo%20Bar&baz=Foo%20Baz', 'normalizes spaces in both encodings "%20" and "+"'],
787787

788788
['foo[]=1&foo[]=2', 'foo%5B0%5D=1&foo%5B1%5D=2', 'allows array notation'],
789789
['foo=1&foo=2', 'foo=2', 'merges repeated parameters'],
790790
['pa%3Dram=foo%26bar%3Dbaz&test=test', 'pa%3Dram=foo%26bar%3Dbaz&test=test', 'works with encoded delimiters'],
791791
['0', '0=', 'allows "0"'],
792-
['Jane Doe&John%20Doe', 'Jane_Doe=&John_Doe=', 'normalizes encoding in keys'],
793-
['her=Jane Doe&him=John%20Doe', 'her=Jane%20Doe&him=John%20Doe', 'normalizes encoding in values'],
792+
['Foo Bar&Foo%20Baz', 'Foo_Bar=&Foo_Baz=', 'normalizes encoding in keys'],
793+
['bar=Foo Bar&baz=Foo%20Baz', 'bar=Foo%20Bar&baz=Foo%20Baz', 'normalizes encoding in values'],
794794
['foo=bar&&&test&&', 'foo=bar&test=', 'removes unneeded delimiters'],
795795
['formula=e=m*c^2', 'formula=e%3Dm%2Ac%5E2', 'correctly treats only the first "=" as delimiter and the next as value'],
796796

src/Symfony/Component/Routing/Matcher/Dumper/CompiledUrlMatcherTrait.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,16 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
135135
}
136136
}
137137

138-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
139-
// no-op
140-
} elseif (preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
141-
$matches = $n;
142-
} else {
143-
$hasTrailingSlash = true;
144-
}
145-
146-
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
138+
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
139+
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
147140
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
148141
return $allow = $allowSchemes = [];
149142
}
150-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
151-
continue;
152-
}
143+
continue;
144+
}
145+
146+
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
147+
$matches = $n;
153148
}
154149

155150
foreach ($vars as $i => $v) {

src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,18 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
156156
continue;
157157
}
158158

159-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar = preg_match('#\{\w+\}/?$#', $route->getPath())) {
160-
// no-op
161-
} elseif (preg_match($regex, $trimmedPathinfo, $m)) {
162-
$matches = $m;
163-
} else {
164-
$hasTrailingSlash = true;
165-
}
159+
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && preg_match('#\{\w+\}/?$#', $route->getPath());
166160

167-
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
161+
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
168162
if ($supportsTrailingSlash && (!$requiredMethods || \in_array('GET', $requiredMethods))) {
169163
return $this->allow = $this->allowSchemes = [];
170164
}
171-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
172-
continue;
173-
}
165+
166+
continue;
167+
}
168+
169+
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $trimmedPathinfo, $m)) {
170+
$matches = $m;
174171
}
175172

176173
$hostMatches = [];

src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,12 @@ public function testSlashWithVerb()
731731
$this->assertSame(['_route' => 'b'], $matcher->match('/bar/'));
732732

733733
$coll = new RouteCollection();
734-
$coll->add('a', new Route('/dav/{foo<.*>?}', [], [], [], '', [], ['GET', 'OPTIONS']));
734+
$coll->add('a', new Route('/dav/{foo}', [], ['foo' => '.*'], [], '', [], ['GET', 'OPTIONS']));
735735

736736
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
737737
$expected = [
738738
'_route' => 'a',
739-
'foo' => 'files/bar',
739+
'foo' => 'files/bar/',
740740
];
741741
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
742742
}
@@ -766,6 +766,17 @@ public function testSlashAndVerbPrecedence()
766766
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
767767
}
768768

769+
public function testGreedyTrailingRequirement()
770+
{
771+
$coll = new RouteCollection();
772+
$coll->add('a', new Route('/{a}', [], ['a' => '.+']));
773+
774+
$matcher = $this->getUrlMatcher($coll);
775+
776+
$this->assertEquals(['_route' => 'a', 'a' => 'foo'], $matcher->match('/foo'));
777+
$this->assertEquals(['_route' => 'a', 'a' => 'foo/'], $matcher->match('/foo/'));
778+
}
779+
769780
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
770781
{
771782
return new UrlMatcher($routes, $context ?: new RequestContext());

src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,17 @@ public function eraseCredentials()
136136
*/
137137
public function serialize()
138138
{
139-
return serialize(
140-
[
141-
\is_object($this->user) ? clone $this->user : $this->user,
142-
$this->authenticated,
143-
array_map(function ($role) { return clone $role; }, $this->roles),
144-
$this->attributes,
145-
]
146-
);
139+
$serialized = [$this->user, $this->authenticated, $this->roles, $this->attributes];
140+
141+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
147142
}
148143

149144
/**
150145
* {@inheritdoc}
151146
*/
152147
public function unserialize($serialized)
153148
{
154-
list($this->user, $this->authenticated, $this->roles, $this->attributes) = unserialize($serialized);
149+
list($this->user, $this->authenticated, $this->roles, $this->attributes) = \is_array($serialized) ? $serialized : unserialize($serialized);
155150
}
156151

157152
/**
@@ -231,6 +226,19 @@ public function __toString()
231226
return sprintf('%s(user="%s", authenticated=%s, roles="%s")', $class, $this->getUsername(), json_encode($this->authenticated), implode(', ', $roles));
232227
}
233228

229+
/**
230+
* @internal
231+
*/
232+
protected function doSerialize($serialized, $isCalledFromOverridingMethod)
233+
{
234+
if (null === $isCalledFromOverridingMethod) {
235+
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3);
236+
$isCalledFromOverridingMethod = isset($trace[2]['function'], $trace[2]['object']) && 'serialize' === $trace[2]['function'] && $this === $trace[2]['object'];
237+
}
238+
239+
return $isCalledFromOverridingMethod ? $serialized : serialize($serialized);
240+
}
241+
234242
private function hasUserChanged(UserInterface $user)
235243
{
236244
if (!($this->user instanceof UserInterface)) {

src/Symfony/Component/Security/Core/Authentication/Token/AnonymousToken.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ public function getSecret()
5959
*/
6060
public function serialize()
6161
{
62-
return serialize([$this->secret, parent::serialize()]);
62+
$serialized = [$this->secret, parent::serialize(true)];
63+
64+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
6365
}
6466

6567
/**
6668
* {@inheritdoc}
6769
*/
6870
public function unserialize($serialized)
6971
{
70-
list($this->secret, $parentStr) = unserialize($serialized);
72+
list($this->secret, $parentStr) = \is_array($serialized) ? $serialized : unserialize($serialized);
7173
parent::unserialize($parentStr);
7274
}
7375
}

src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,17 @@ public function eraseCredentials()
7979
*/
8080
public function serialize()
8181
{
82-
return serialize([$this->credentials, $this->providerKey, parent::serialize()]);
82+
$serialized = [$this->credentials, $this->providerKey, parent::serialize(true)];
83+
84+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
8385
}
8486

8587
/**
8688
* {@inheritdoc}
8789
*/
8890
public function unserialize($str)
8991
{
90-
list($this->credentials, $this->providerKey, $parentStr) = unserialize($str);
92+
list($this->credentials, $this->providerKey, $parentStr) = \is_array($str) ? $str : unserialize($str);
9193
parent::unserialize($parentStr);
9294
}
9395
}

src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,17 @@ public function getCredentials()
9494
*/
9595
public function serialize()
9696
{
97-
return serialize([
98-
$this->secret,
99-
$this->providerKey,
100-
parent::serialize(),
101-
]);
97+
$serialized = [$this->secret, $this->providerKey, parent::serialize(true)];
98+
99+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
102100
}
103101

104102
/**
105103
* {@inheritdoc}
106104
*/
107105
public function unserialize($serialized)
108106
{
109-
list($this->secret, $this->providerKey, $parentStr) = unserialize($serialized);
107+
list($this->secret, $this->providerKey, $parentStr) = \is_array($serialized) ? $serialized : unserialize($serialized);
110108
parent::unserialize($parentStr);
111109
}
112110
}

src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ public function eraseCredentials()
9191
*/
9292
public function serialize()
9393
{
94-
return serialize([$this->credentials, $this->providerKey, parent::serialize()]);
94+
$serialized = [$this->credentials, $this->providerKey, parent::serialize(true)];
95+
96+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
9597
}
9698

9799
/**
98100
* {@inheritd 6C1C oc}
99101
*/
100102
public function unserialize($serialized)
101103
{
102-
list($this->credentials, $this->providerKey, $parentStr) = unserialize($serialized);
104+
list($this->credentials, $this->providerKey, $parentStr) = \is_array($serialized) ? $serialized : unserialize($serialized);
103105
parent::unserialize($parentStr);
104106
}
105107
}

0 commit comments

Comments
 (0)
0