Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1240641

Browse files
alonbardavidpetebacondarwin
authored andcommitted
feat($cookieStore): $cookieStore.get now parses blank string as blank string
closes #1918
1 parent f1a34f0 commit 1240641

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ngCookies/cookies.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ angular.module('ngCookies', ['ng']).
139139
* @returns {Object} Deserialized cookie value.
140140
*/
141141
get: function(key) {
142-
return angular.fromJson($cookies[key]);
142+
var value = $cookies[key];
143+
return value ? angular.fromJson(value) : value;
143144
},
144145

145146
/**

test/ngCookies/cookiesSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,15 @@ describe('$cookieStore', function() {
125125
$rootScope.$digest();
126126
expect($browser.cookies()).toEqual({});
127127
}));
128+
it('should handle empty string value cookies', inject(function ($cookieStore, $browser, $rootScope) {
129+
$cookieStore.put("emptyCookie",'');
130+
$rootScope.$digest();
131+
expect($browser.cookies()).
132+
toEqual({ 'emptyCookie': '""' });
133+
expect($cookieStore.get("emptyCookie")).toEqual('');
134+
135+
$browser.cookieHash['blankCookie'] = '';
136+
$browser.poll();
137+
expect($cookieStore.get("blankCookie")).toEqual('');
138+
}))
128139
});

0 commit comments

Comments
 (0)