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

Skip to content

[BrowserKit] BC-Break with casting parameters to string #38651

Closed
@michaljusiega

Description

@michaljusiega

Symfony version(s) affected: 5.2.0-BETA2

Description
My CI/CD tests are crazy after upgrade to Symfony 5.2.0-BETA2. So...
All parameters as null value are casting to string. So (string) null is '' (empty string).

How to reproduce

$browserClient = self::createClient();
$browserClient->request(Request::METHOD_GET, '/url', ['string_value' => 'string', 'nullable_value' => null]);
/** @var \Symfony\Component\HttpFoundation\Request $request */
dd($request->query->all());

In Symfony 5.2-BETA2:

array:2 [
  "string_value" => "string"
  "nullable_value" => ""
]

In Symfony 5.1 and lower:

array:2 [
  "string_value" => "string"
  "nullable_value" => null
]

Possible Solution
Workaround and ignore nullable values:

        array_walk_recursive($parameters, static function (&$value) {
            $value = (string) $value;
        });

to:

        array_walk_recursive($parameters, static function (&$value) {
            if (null !== $value) {
                $value = (string) $value;
            }
        });

Additional context
See #37740 and #37755

I'm ready to make PR.

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