Comma cookie values ​​parsed twice in ZF2

I use the ZF2 Zend \ HTTP \ Header \ SetCookie class to set a named cookie. The trap is that a value is a list of the meanings of a single word, separated by commas. This works fine today as follows:

$translations_cookie = new SetCookie('translations', implode(',', $requested_translations), null, null, null, false, false, null, null); $response->getHeaders()->addHeader($translations_cookie); 

The cookie value gets the encoding, and the commas become %2C , and everything is fine between browsers. Returning the value later and comma-separated is just fine.

The problem is that the cookie does not have a specific path value and by default any folder from which it was launched is used. I just came across a situation where it breaks, and I need to make the cookie path be the root of the site. I thought it would be as simple as adding the right value:

 $translations_cookie = new SetCookie('translations', implode(',', $requested_translations), null, '/', null, false, false, null, null); $response->getHeaders()->addHeader($translations_cookie); 

It looks like this path is just fine, but now the cookie value is messed up! Only the last element of the array passes it to the actual cookie that is being set. No matter how many elements in the array they are discarded, and only the last element falls into the cookie header.

Any idea what and how I can fix it? Is this a bug in ZF2 or am I something wrong?

Edit: Yes. I tried pre-encoding the value with urlencode() before passing it to the cookie function, but that did not change the final result. Using a different separator fixes this problem with Zend, but creates incompatibility between other parts of my program, including third-party code and existing URLs, and will mean that I have to update cookies and update old sessions - a circus that I don’t want to join if i can help.

+4
source share
1 answer

This may sound silly, but just delete the cookies or try a different browser (not a private browser) :)

-one
source

All Articles