aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/services.js21
-rw-r--r--test/servicesSpec.js12
2 files changed, 16 insertions, 17 deletions
diff --git a/src/services.js b/src/services.js
index 7742b174..de65e30f 100644
--- a/src/services.js
+++ b/src/services.js
@@ -1118,6 +1118,8 @@ angularServiceInject('$cookies', function($browser) {
})();
//at the end of each eval, push cookies
+ //TODO: this should happen before the "delayed" watches fire, because if some cookies are not
+ // strings or browser refuses to store some cookies, we update the model in the push fn.
this.$onEval(PRIORITY_LAST, push);
return cookies;
@@ -1128,6 +1130,7 @@ angularServiceInject('$cookies', function($browser) {
*/
function push(){
var name,
+ value,
browserCookies,
updated;
@@ -1140,15 +1143,22 @@ angularServiceInject('$cookies', function($browser) {
//update all cookies updated in $cookies
for(name in cookies) {
- if (cookies[name] !== lastCookies[name]) {
- $browser.cookies(name, cookies[name]);
+ value = cookies[name];
+ if (!isString(value)) {
+ if (isDefined(lastCookies[name])) {
+ cookies[name] = lastCookies[name];
+ } else {
+ delete cookies[name];
+ }
+ } else if (value !== lastCookies[name]) {
+ $browser.cookies(name, value);
updated = true;
}
}
//verify what was actually stored
if (updated){
- updated = !updated;
+ updated = false;
browserCookies = $browser.cookies();
for (name in cookies) {
@@ -1161,11 +1171,6 @@ angularServiceInject('$cookies', function($browser) {
}
updated = true;
}
-
- }
-
- if (updated) {
- rootScope.$eval();
}
}
}
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index eebcf7dc..0569c54a 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -696,20 +696,14 @@ describe("service", function(){
});
- it('should ignore non-string values when asked to create a cookie', function() {
+ it('should drop or reset any cookie that was set to a non-string value', function() {
scope.$cookies.nonString = [1, 2, 3];
- scope.$eval();
- expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'});
- expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'});
- });
-
-
- it('should drop any null or undefined properties', function() {
scope.$cookies.nullVal = null;
scope.$cookies.undefVal = undefined;
+ scope.$cookies.preexisting = function(){};
scope.$eval();
-
expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'});
+ expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'});
});