voltace / browser-cookies

Tiny cookies library for the browser
The Unlicense
89 stars 19 forks source link

Empty string returned as null when using IE<11 #1

Closed voltace closed 9 years ago

voltace commented 9 years ago

Using IE<11 null is returned when reading a cookie which has an empty string as value. The expected result would be "".

The bug is caused by assuming an = sign is always present for each cookie in document.cookie. However, IE<11 emits the = sign for cookies with an empty string value:

document.cookie = "name=";
console.log(document.cookie)
"name"

Note that other browsers and IE>=11 do include the = sign:

document.cookie = "name=";
console.log(document.cookie)
"name="