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

Commit

Permalink
feat($cookieStore): $cookieStore.get now parses blank string as blank…
Browse files Browse the repository at this point in the history
… string

closes #1918
  • Loading branch information
alonbardavid authored and petebacondarwin committed May 8, 2013
1 parent 4f2e360 commit cf4729f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ngCookies/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

/**
Expand Down
11 changes: 11 additions & 0 deletions test/ngCookies/cookiesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}))
});

0 comments on commit cf4729f

Please sign in to comment.