Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@mvanduijker

Description

@mvanduijker
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.