8000 Add check and tests for public properties · symfony/symfony@cdfd7a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit cdfd7a0

Browse files
committed
Add check and tests for public properties
1 parent 31d6937 commit cdfd7a0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
298298
if ($v instanceof \stdClass) {
299299
$v = (array) $v;
300300
array_walk_recursive($v, $caster);
301-
} elseif (\is_object($v) && method_exists($v, '__toString')) {
301+
} elseif (\is_object($v) && !get_object_vars($v) && method_exists($v, '__toString')) {
302302
$v = (string) $v;
303303
}
304304
});

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ public function valuesProvider(): array
140140
'boolean-false' => ['?foo=0', 'foo', false],
141141
'boolean-true' => ['?foo=1', 'foo', true],
142142
'object implementing __toString()' => ['?foo=bar', 'foo', new StringableObject()],
143+
'object implementing __toString() but has public property' => ['?foo%5Bfoo%5D=property', 'foo', new StringableObjectWithPublicProperty()],
143144
'object implementing __toString() in nested array' => ['?foo%5Bbaz%5D=bar', 'foo', ['baz' => new StringableObject()]],
144-
'stdClass' => ['foo%5Bbaz%5D=bar', '?foo', $stdClass],
145+
'object implementing __toString() in nested array but has public property' => ['?foo%5Bbaz%5D%5Bfoo%5D=property', 'foo', ['baz' => new StringableObjectWithPublicProperty()]],
146+
'stdClass' => ['?foo%5Bbaz%5D=bar', 'foo', $stdClass],
145147
'stdClass in nested stdClass' => ['?foo%5Bnested%5D%5Bbaz%5D=bar', 'foo', $nestedStdClass],
146-
'not stringable object' => ['', 'foo', new NotStringableObject()],
148+
'non stringable object' => ['', 'foo', new NonStringableObject()],
149+
'non stringable object but has public property' => ['?foo%5Bfoo%5D=property', 'foo', new NonStringableObjectWithPublicProperty()],
147150
];
148151
}
149152

@@ -920,6 +923,21 @@ public function __toString()
920923
}
921924
}
922925

923-
class NotStringableObject
926+
class StringableObjectWithPublicProperty
924927
{
928+
public $foo = 'property';
929+
930+
public function __toString()
931+
{
932+
return 'bar';
933+
}
934+
}
935+
936+
class NonStringableObject
937+
{
938+
}
939+
940+
class NonStringableObjectWithPublicProperty
941+
{
942+
public $foo = 'property';
925943
}

0 commit comments

Comments
 (0)
0