nhsuk / cookie-consent

In-house solution for managing cookies on nhs.uk
MIT License
19 stars 7 forks source link

Handle badly formatted cookie value #175

Open pufferfish101007 opened 9 months ago

pufferfish101007 commented 9 months ago

If the cookie cannot be parsed as valid JSON, reset the cookie to a sensible default and return this new value. Adds/updates unit tests to reflect this change. The 'sensible default value' is just { ...defaultConsent, version: COOKIE_VERSION i.e. { consented: false, marketing: false, necessary: true, preferences: false, statistics: false, version: 4 }. This means that the cookie banner will be shown if the cookie is invalid upon page load; I think this makes sense as we don't know if the user has consented or not. Manually tested in chrome 121 and firefox 122; all unit tests pass.