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

Skip to content
8000

Commit adbdec8

Browse files
Merge branch '4.1' into 4.2
* 4.1: [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 Remove gendered pronouns Replace gender by eye color in tests [Security] dont do nested calls to serialize()
2 parents 6b611d5 + 05071a4 commit adbdec8

File tree

31 files changed

+183
-105
lines changed

31 files changed

+183
-105
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/Tests/DependencyInjection/ConfigurationTest.php

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

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

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/PhpMatcherTrait.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,16 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
130130
continue;
131131
}
132132

133-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
134-
// no-op
135-
} elseif (preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
136-
$matches = $n;
137-
} else {
138-
$hasTrailingSlash = true;
139-
}
140-
141-
if ('/' !== $pathinfo && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
133+
$hasTrailingVar = $trimmedPathinfo !== $pathinfo && $hasTrailingVar;
134+
if ('/' !== $pathinfo && !$hasTrailingVar && $hasTrailingSlash === ($trimmedPathinfo === $pathinfo)) {
142135
if ($supportsRedirections && (!$requiredMethods || isset($requiredMethods['GET']))) {
143136
return $allow = $allowSchemes = [];
144137
}
145-
if ($trimmedPathinfo === $pathinfo || !$hasTrailingVar) {
146-
continue;
147-
}
138+
continue;
139+
}
140+
141+
if ($hasTrailingSlash && $hasTrailingVar && preg_match($regex, $this->matchHost ? $host.'.'.$trimmedPathinfo : $trimmedPathinfo, $n) && $m === (int) $n['MARK']) {
142+
$matches = $n;
148143
}
149144

150145
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
@@ -711,12 +711,12 @@ public function testSlashWithVerb()
711711
$this->assertSame(['_route' => 'b'], $matcher->match('/bar/'));
712712

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

716716
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
717717
$expected = [
718718
'_route' => 'a',
719-
'foo' => 'files/bar',
719+
'foo' => 'files/bar/',
720720
];
721721
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
722722
}
@@ -746,6 +746,17 @@ public function testSlashAndVerbPrecedence()
746746
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
747747
}
748748

749+
public function testGreedyTrailingRequirement()
750+
{
751+
$coll = new RouteCollection();
752+
$coll->add('a', new Route('/{a}', [], ['a' => '.+']));
753+
754+
$matcher = $this->getUrlMatcher($coll);
755+
756+
$this->assertEquals(['_route' => 'a', 'a' => 'foo'], $matcher->match('/foo'));
757+
$this->assertEquals(['_route' => 'a', 'a' => 'foo/'], $matcher->match('/foo/'));
758+
}
759+
749760
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
750761
{
751762
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
* {@inheritdoc}
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