symfony: VarDump file corruption

Symfony version(s) affected

6.1.7

Description

Hello,

I just discovered a strange thing while trying to dumping an object in a controller that produce a PDF.

Given the following controller, and considering that generateBadge return the string of PDF, if I got the file corrupted if I add a dump('test') but only if I do a GET request. If the PDF is generated from a POST request the file is correct.

/**
 * Generate a PDF file (e-badge)
 *
 * @Route("/badge/{id}", name="generate_badge", methods={"GET", "POST"}, requirements={"id" = "\d+"})
 */
public function generateBadge(BadgeGenerator $generator, int $id): Response
{
    $content = $generator->generateBadge($id);
    dump('test');
    $this->logger->info($content);

    return new Response($content, 200, [
        'Content-Type'   => 'application/pdf; charset=UTF-8',
        'Accept-Ranges'  => 'byte',
        'Content-Length' => strlen($content),
        'Content-disposition' => 'inline; filename=badge.pdf',
    ]);
}

Please note that the $content is correct in GET or POST.

image

Here the resulting file content when generating from a GET request. As you can see the dump is in the file:

image

Is it expected or am I missing something?

How to reproduce

Create a

/**
 * @Route("/badge/{id}", name="generate_badge", methods={"GET", "POST"})
 */
public function generateBadge(): Response
{
    dump('test');

    return new Response('', 200, [
        'Content-Type'   => 'application/pdf; charset=UTF-8',
        'Accept-Ranges'  => 'byte',
        'Content-disposition' => 'inline; filename=badges.pdf',
    ]);
}

And check the source of generated file In GET request:

MeetingController.php on line 546:
"test"

The file should be empty.

Possible Solution

It seems to me that the header is not taken correctly into account by the VarDumper.

Additional Context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

Hello, yes sure I will try to do it using the symfony demo app tomorrow.

Just to let you know, I just checked quickly using the Symfony demo (SF6.1.6) app with same route / controller (reproducer) as in my app (SF6.1.7) I don’t have the file corruption.

I’m trying to find the differences between my app and the Symfony demo app.