8000 [HttpFoundation] Fix `\Stringable` support in `InputBag::get()` · symfony/symfony@83130b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83130b6

Browse files
committed
[HttpFoundation] Fix \Stringable support in InputBag::get()
1 parent c158a6a commit 83130b6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Symfony/Component/HttpFoundation/InputBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function get(string $key, mixed $default = null): string|int|float|bool|n
3333

3434
$value = parent::get($key, $this);
3535

36-
if (null !== $value && $this !== $value && !\is_scalar($value)) {
36+
if (null !== $value && $this !== $value && !\is_scalar($value) && !$value instanceof \Stringable) {
3737
throw new BadRequestException(sprintf('Input value "%s" contains a non-scalar value.', $key));
3838
}
3939

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class InputBagTest extends TestCase
1919
{
2020
public function testGet()
2121
{
22-
$bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false]);
22+
$bag = new InputBag(['foo' => 'bar', 'null' => null, 'int' => 1, 'float' => 1.0, 'bool' => false, 'stringable' => new class implements \Stringable { public function __toString(): string { return 'strval'; }}]);
2323

2424
$this->assertSame('bar', $bag->get('foo'), '->get() gets the value of a string parameter');
2525
$this->assertSame('default', $bag->get('unknown', 'default'), '->get() returns second argument as default if a parameter is not defined');
2626
$this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set');
2727
$this->assertSame(1, $bag->get('int'), '->get() gets the value of an int parameter');
2828
$this->assertSame(1.0, $bag->get('float'), '->get() gets the value of a float parameter');
29+
$this->assertSame('strval', $bag->get('stringable'), '->get() gets the string value of a \Stringable parameter');
2930
$this->assertFalse($bag->get('bool'), '->get() gets the value of a bool parameter');
3031
}
3132

0 commit comments

Comments
 (0)
0