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

Saving an integer with $cookies doesn't work, and doesn't throw an error. #6151

Closed
MattijsKneppers opened this issue Feb 6, 2014 · 4 comments

Comments

@MattijsKneppers
Copy link

Saving an integer as a cookie like so:

$cookies.step = 2; 

doesn't result in a cookie being written.

Currently, for someone who is not familiar with cookies, it takes quite some head-scratching before it becomes clear what the problem is when one cookie is written correctly but the other is not.

It would be great if trying to do this would throw an error.

@caitp caitp self-assigned this Feb 12, 2014
@caitp caitp added this to the 1.2.13 milestone Feb 12, 2014
@caitp
Copy link
Contributor

caitp commented Feb 12, 2014

If I can write a failing test and fix this tonight, I think we can ship this for 1.2.13

@MattijsKneppers
Copy link
Author

I'm not sure this is the best approach. With this solution, people will see their integer value coming back as a string. Except that it will take some frantic debugging before they actually find out where that weird problem originated.

I would vote for simply throwing a warning when someone tries to store an integer. 'Warning: integers can not be stored as cookies. Please convert your integer to a string'.

@caitp
Copy link
Contributor

caitp commented Feb 13, 2014

Hm, I see your point. I'm not sure. What about warning and calling toString() if it's available?

@btford btford modified the milestones: 1.2.14, 1.2.13 Feb 15, 2014
@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.1, 1.2.14 Mar 1, 2014
@btford btford modified the milestones: 1.3.0-beta.2, 1.3.0-beta.1 Mar 10, 2014
@tbosch tbosch modified the milestones: 1.3.0-beta.3, 1.3.0-beta.2 Mar 14, 2014
caitp added a commit to caitp/angular.js that referenced this issue Mar 18, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, a warning is emitted, so that there is some idea of where the
error is occurring.

Closes angular#6151
caitp added a commit to caitp/angular.js that referenced this issue Mar 18, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, a warning is emitted, so that there is some idea of where the
error is occurring.

Closes angular#6151
@IgorMinar
Copy link
Contributor

we should convert the value to string just like many apis do (including document.cookie)

caitp added a commit to caitp/angular.js that referenced this issue Mar 19, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, the value is converted to string before being stored, and the
value is not dropped. Serialization may be customized using the toString() method of an object's
prototype.

Closes angular#6151
caitp added a commit to caitp/angular.js that referenced this issue Mar 19, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, the value is converted to string before being stored, and the
value is not dropped. Serialization may be customized using the toString() method of an object's
prototype.

Closes angular#6151
caitp added a commit to caitp/angular.js that referenced this issue Mar 19, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, the value is converted to string before being stored, and the
value is not dropped. Serialization may be customized using the toString() method of an object's
prototype.

Closes angular#6151
@caitp caitp closed this as completed in 3652831 Mar 19, 2014
caitp added a commit that referenced this issue Mar 21, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, the value is converted to string before being stored, and the
value is not dropped. Serialization may be customized using the toString() method of an object's
prototype.

Closes #6151
Closes #6220
tbosch pushed a commit to tbosch/angular.js that referenced this issue Mar 21, 2014
Previously, non-string values stored in $cookies would be removed, without warning the user, and
causing difficulty debugging. Now, the value is converted to string before being stored, and the
value is not dropped. Serialization may be customized using the toString() method of an object's
prototype.

Closes angular#6151
Closes angular#6220
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.