carhartl/jquery-cookie — Issue #39: IE8 + Empty String Cookies, returning null instead of ''
Author: sexytyranno
Created: 2011-11-23 00:03:48+00:00
State: open

I don't have a test case written up for you, but I can at least describe the issue. :)

In IE8, when you set a cookie to an empty value, it encodes it in a rather odd fashion.

Code on our index (simplified to the point):

```javascript
function hasCookie(name) { return (jQuery.cookie(name) != null) }
function runblah() {
if(hasCookie('referrer')) { return true; }

jQuery.cookie('referrer', document.referrer, {
path: '/',
domain: 'blah.com',
expires: 1
});
window.location = "/blah.cgi?returnTo=/";
}
```

What happens on IE8:

You visit index, with no referrer. (document.referrer is '', NOT NULL, per IE8's JS Console)

runblah() runs, sets referrer cookie to '', then sends us to blah.cgi.

blah.cgi does some back-end accounting stuff, then sends us back to index.

Index loads and runs again. On FF and Chrome, jQuery.cookie('referrer') returns '' as it should. On IE8, however, it returns null. In our case, this caused a nasty redirection loop.

When we inspected document.cookie, we found that it was being set to the following: "x=y; y=z; referrer" (x and y are placeholders for other cookies that showed up in there)