8000 [HttpKernel] ExceptionListener does not duplicate _format request attribute properly · Issue #8777 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] ExceptionListener does not duplicate _format request attribute properly #8777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
richardfullmer opened this issue Aug 17, 2013 · 0 comments

Comments

@richardfullmer
Copy link

Found while working with FOSRestBundle's FormatNegotiator.

In HttpKernel/EventListener/ExceptionListener.php

$attributes = array(
    '_controller' => $this->controller,
    'exception'   => FlattenException::create($exception),
    'logger'      => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
    'format'      => $request->getRequestFormat(),
);

$request = $request->duplicate(null, null, $attributes);

Whereas the $request->getRequestFormat() line retrieves the format from the attribute bag as _format.

In HttpFoundation/Request.php

public function getRequestFormat($default = 'html')
{
    if (null === $this->format) {
        $this->format = $this->get('_format', $default);
    }

    return $this->format;
}

It seems to me that we shouldn't change _format into format on the request attribute bag while duplicating a request.

It breaks FOSRestBundle's exception handling by not being able to correctly pass the original request's format into the FormatNegotiation library. Consequently, my json comes out as html for all 403 errors... 👎

fabpot added a commit that referenced this issue Aug 22, 2013
This PR was merged into the 2.2 branch.

Discussion
----------

[HttpKernel] Fix request _format duplication for HttpKernel's ExceptionListener

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8777, #8778
| License       | MIT

This is a better fix for #8777.

Commits
-------

f946108 fixed the format of the request used to render an exception
@fabpot fabpot closed this as completed Aug 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0