diff --git a/HISTORY.md b/HISTORY.md index 2214bce1..ab571e33 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 3.13.2 / 2020-05-21 + +- fix: null values should delete cookies + # 3.13.1 / 2020-05-04 - refactor: remove third party dependency ndhoule/each diff --git a/lib/cookie.js b/lib/cookie.js index f8b01800..c8238e3b 100644 --- a/lib/cookie.js +++ b/lib/cookie.js @@ -73,7 +73,7 @@ Cookie.prototype.options = function(options) { Cookie.prototype.set = function(key, value) { try { value = window.JSON.stringify(value); - cookie(key, value, clone(this._options)); + cookie(key, value === 'null' ? null : value, clone(this._options)); return true; } catch (e) { return false; diff --git a/package.json b/package.json index 131bdfb7..cf764d9d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@segment/analytics.js-core", "author": "Segment ", - "version": "3.13.1", + "version": "3.13.2", "description": "The hassle-free way to integrate analytics into any web application.", "keywords": [ "analytics", diff --git a/test/cookie.test.js b/test/cookie.test.js index 2e0e3226..3a67ca56 100644 --- a/test/cookie.test.js +++ b/test/cookie.test.js @@ -49,6 +49,11 @@ describe('cookie', function() { cookie.remove('cookie-remove'); assert(cookie.get('cookie-remove') === null); }); + + it('null cookie should be null after setting', function() { + cookie.set('cookie-null', null); + assert(cookie.get('cookie-null') === null); + }); }); describe('#options', function() {