0

I was debugging an issue and the root cause was a cookie was being set with a "," in the value

Below was the origional code used:

setCookie(cookieName, {
    sent: new Date().toUTCString(),
    payload: payload,
    updated: new Date().toUTCString()
});

This format, along with being a no-no, was ignored in Chrome and passed QA, but in Mac OS Safari is resulting in a cookie where the date is being split and assiging the value as it's own cookie

Exspected
cookieName                              Mon 08 Nov 2017 21:38:05GMT&nextValue=...

Actual
cookieName                              Mon
Mon 08 Nov 2017 21:38:05GMT&nextValue   ...

I am since fixed the date format but I cannot seem to remove the bad cookie, which is causing issues.

Parsing the document.cookie into pair, I can get the name of the bad cookie

But if I try to remove using $.removeCookie('Mon 08 Nov 2017 21:38:05GMT&nextValue') I see the console log returns true, but yet, the cookie remains.

I have also tried setting to the cookie to null before delelting, but this created a new cookie with replaced spaces as "%20" $.cookie('Mon 08 Nov 2017 21:38:05GMT&nextValue', null)

Anyone have any suggestions for removed a rouge cookie which has spaced in the name? I have tried replacing with %20, to no avail.

atagref
  • 1
  • 1
  • Have you tried removing all cookies, like [here](https://stackoverflow.com/questions/19470517/delete-all-cookies-with-jquery-and-set-new) and then resetting the cookies you want..or is that not a viable option for you at this point? – Michael Evans Nov 08 '17 at 22:26
  • NM, ending up not using jquery cookie and just doing it in JS document.cookie = "Mon 08 Nov 2017 21:38:05GMT&nextValue" + "=; expires=Thu, 01 Jan 1970 00:00:01 GMT" – atagref Nov 08 '17 at 22:55

0 Answers0