8000 [HttpFoundation] ksort in HeaderBag __toString function causes issues for ResponseHeaderBag · Issue #7130 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] ksort in HeaderBag __toString function causes issues for ResponseHeaderBag #7130

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
arrowplum opened this issue Feb 19, 2013 · 2 comments

Comments

@arrowplum
Copy link

The ksort in the __toString function mutates HeaderBag's headers array. ResponseHeaderBag's allPreserveCase method relies on the order of the header array since it keeps a parallel array with header names.

//in Response class

       var_dump($this->headers);
       var_dump($this->headers->allPreserveCase());

if toString has been calls results in something like:

//headers
object(Symfony\Component\HttpFoundation\ResponseHeaderBag)[181]
  protected 'computedCacheControl' => 
    array (size=1)
      'no-cache' => boolean true
  protected 'cookies' => 
    array (size=0)
      empty
  protected 'headerNames' => 
    array (size=3)
      'cache-control' => string 'Cache-Control' (length=13)
      'date' => string 'Date' (length=4)
      'content-type' => string 'Content-Type' (length=12)
  protected 'headers' => 
    array (size=3)
      'cache-control' => 
        array (size=1)
          0 => string 'no-cache' (length=8)
      'content-type' => 
        array (size=1)
          0 => string 'text/html; charset=UTF-8' (length=24)
      'date' => 
        array (size=1)
          0 => string 'Tue, 19 Feb 2013 22:36:39 GMT' (length=29)
  protected 'cacheControl' => 
    array (size=0)
      empty

//allPreserveCase
array (size=3)
  'Cache-Control' => 
    array (size=1)
      0 => string 'no-cache' (length=8)
  'Date' => 
    array (size=1)
      0 => string 'text/html; charset=UTF-8' (length=24)
  'Content-Type' => 
    array (size=1)
      0 => string 'Tue, 19 Feb 2013 22:36:39 GMT' (length=29)

Since sendHeaders uses allPreserveCase, the headers have values and names mixed up.

@arrowplum
Copy link
Author

While the mutating ksort was the first part of the cause, it looks like the real problem is from this commit 63a228c a few months ago which caused the sendHeaders to try and preserve case by relying on the parallel arrays.

@fabpot
Copy link
Member
fabpot commented Feb 26, 2013

fixed in #7189

< 620F div class="d-flex">

@fabpot fabpot closed this as completed Feb 26, 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