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

Skip to content

Commit 78c23c7

Browse files
Merge branch '3.4' into 4.1
* 3.4: skip native serialize among child and parent serializable objects [Routing] backport tests from 4.1 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 55ffdf9 + b4357d7 commit 78c23c7

27 files changed

+168
-79
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
644644
->fixXmlConfig('package')
645645
->children()
646646
->arrayNode('packages')
647+
->normalizeKeys(false)
647648
->useAttributeAsKey('name')
648649
->prototype('array')
649650
->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
@@ -100,6 +100,35 @@ public function testAssetsCanBeEnabled()
100100
$this->assertEquals($defaultConfig, $config['assets']);
101101
}
102102

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

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
@@ -160,9 +160,9 @@ public function searchAndRenderBlock(FormView $view, $blockNameSuffix, array $va
160160
// to implement a custom "choice_widget" block (no matter in which theme),
161161
// or to fallback to the block of the parent type, which would be
162162
// "form_widget" in this example (again, no matter in which theme).
163-
// If the designer wants to explicitly fallback to "form_widget" in his
164-
// custom "choice_widget", for example because he only wants to wrap
165-
// a <div> around the original implementation, he can simply call the
163+
// If the designer wants to explicitly fallback to "form_widget" in their
164+
// custom "choice_widget", for example because they only want to wrap
165+
// a <div> around the original implementation, they can simply call the
166166
// widget() function again to render the block for the parent type.
167167
//
168168
// 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/Tests/Matcher/UrlMatcherTest.php

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

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

713713
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
714714
$expected = [
715715
'_route' => 'a',
716-
'foo' => 'files/bar',
716+
'foo' => 'files/bar/',
717717
];
718718
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
719719
}
@@ -743,6 +743,17 @@ public function testSlashAndVerbPrecedence()
743743
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
744744
}
745745

746+
public function testGreedyTrailingRequirement()
747+
{
748+
$coll = new RouteCollection();
749+
$coll->add('a', new Route('/{a}', [], ['a' => '.+']));
750+
751+
$matcher = $this->getUrlMatcher($coll);
752+
753+
$this->assertEquals(['_route' => 'a', 'a' => 'foo'], $matcher->match('/foo'));
754+
$this->assertEquals(['_route' => 'a', 'a' => 'foo/'], $matcher->match('/foo/'));
755+
}
756+
746757
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
747758
{
748759
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
}

src/Symfony/Component/Security/Core/Exception/AccountStatusException.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@ public function setUser(UserInterface $user)
4444
*/
4545
public function serialize()
4646
{
47-
return serialize([
48-
$this->user,
49-
parent::serialize(),
50-
]);
47+
$serialized = [$this->user, parent::serialize(true)];
48+
49+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
5150
}
5251

5352
/**
5453
* {@inheritdoc}
5554
*/
5655
public function unserialize($str)
5756
{
58-
list($this->user, $parentData) = unserialize($str);
57+
list($this->user, $parentData) = \is_array($str) ? $str : unserialize($str);
5958

6059
parent::unserialize($parentData);
6160
}

src/Symfony/Component/Security/Core/Exception/AuthenticationException.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,33 @@ public function setToken(TokenInterface $token)
3838
$this->token = $token;
3939
}
4040

41+
/**
42+
* {@inheritdoc}
43+
*/
4144
public function serialize()
4245
{
43-
return serialize([
46+
$serialized = [
4447
$this->token,
4548
$this->code,
4649
$this->message,
4750
$this->file,
4851
$this->line,
49-
]);
52+
];
53+
54+
return $this->doSerialize($serialized, \func_num_args() ? \func_get_arg(0) : null);
55+
}
56+
57+
/**
58+
* @internal
59+
*/
60+
protected function doSerialize($serialized, $isCalledFromOverridingMethod)
61+
{
62+
if (null === $isCalledFromOverridingMethod) {
63+
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3);
64+
$isCalledFromOverridingMethod = isset($trace[2]['function'], $trace[2]['object']) && 'serialize' === $trace[2]['function'] && $this === $trace[2]['object'];
65+
}
66+
67+
return $isCalledFromOverridingMethod ? $serialized : serialize($serialized);
5068
}
5169

5270
public function unserialize($str)
@@ -57,7 +75,7 @@ public function unserialize($str)
5775
$this->message,
5876
$this->file,
5977
$this->line
60-
) = unserialize($str);
78+
) = \is_array($str) ? $str : unserialize($str);
6179
}
6280

6381
/**

0 commit comments

Comments
 (0)
0