From cf4729faa3e6e0a5178e2064a6f3cfd345686554 Mon Sep 17 00:00:00 2001 From: Illniyar Date: Sat, 20 Apr 2013 23:33:40 +0300 Subject: [PATCH] feat($cookieStore): $cookieStore.get now parses blank string as blank string closes #1918 --- src/ngCookies/cookies.js | 3 ++- test/ngCookies/cookiesSpec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ngCookies/cookies.js b/src/ngCookies/cookies.js index 8b46973f3ac6..683557077688 100644 --- a/src/ngCookies/cookies.js +++ b/src/ngCookies/cookies.js @@ -139,7 +139,8 @@ angular.module('ngCookies', ['ng']). * @returns {Object} Deserialized cookie value. */ get: function(key) { - return angular.fromJson($cookies[key]); + var value = $cookies[key]; + return value ? angular.fromJson(value) : value; }, /** diff --git a/test/ngCookies/cookiesSpec.js b/test/ngCookies/cookiesSpec.js index 435f40b4efc8..674c27748f11 100644 --- a/test/ngCookies/cookiesSpec.js +++ b/test/ngCookies/cookiesSpec.js @@ -125,4 +125,15 @@ describe('$cookieStore', function() { $rootScope.$digest(); expect($browser.cookies()).toEqual({}); })); + it('should handle empty string value cookies', inject(function ($cookieStore, $browser, $rootScope) { + $cookieStore.put("emptyCookie",''); + $rootScope.$digest(); + expect($browser.cookies()). + toEqual({ 'emptyCookie': '""' }); + expect($cookieStore.get("emptyCookie")).toEqual(''); + + $browser.cookieHash['blankCookie'] = ''; + $browser.poll(); + expect($cookieStore.get("blankCookie")).toEqual(''); + })) });