Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MapQueryString doesn't support string value for boolean type #53616

Closed
@mvanduijker

Description

@mvanduijker

Symfony version(s) affected

6.3, 6.4, 7.0

Description

MapQueryString attribute fails parsing string value for boolean type.

Problem is nicely described in this issue #42715
But in this case we know for sure that it's a string (just like the CSV and XML types in AbstractObjectNormalizer.php

Don't know if it's a bug or a feature.

How to reproduce

I expect the following to be false, but true is returned.

Request Url

https://example.com?myBoolean=false

DTO

<?php

readonly class MyDTO 
{
    public function __construct(
        public bool $myBoolean
    )    
}

Controller

<?php

use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Annotation\Route;

class MyController
{
    #[Route('/')]
    public function __invoke(
        #[MapQueryString]
        MyDTO $dto
    ) {
        dd($dto->myBoolean);
    }
}

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions