Permalink
Browse files

fix(angular.toJson): only strip properties beginning with $$, not $

BREAKING CHANGE:

If you expected `toJson` to strip these types of properties before,
you will have to manually do this yourself now.
  • Loading branch information...
rodyhaddad authored and btford committed Feb 15, 2014
1 parent 8c02a49 commit c054288c9722875e3595e6e6162193e0fb67a251
Showing with 9 additions and 4 deletions.
  1. +2 −2 src/Angular.js
  2. +7 −2 test/AngularSpec.js
View
@@ -975,7 +975,7 @@ function bind(self, fn) {
function toJsonReplacer(key, value) {
var val = value;
if (typeof key === 'string' && key.charAt(0) === '$') {
if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
val = undefined;
} else if (isWindow(value)) {
val = '$WINDOW';
@@ -996,7 +996,7 @@ function toJsonReplacer(key, value) {
* @function
*
* @description
* Serializes input into a JSON-formatted string. Properties with leading $ characters will be
* Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
* stripped since angular uses this notation internally.
*
* @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.
View
@@ -1131,8 +1131,13 @@ describe('angular', function() {
});
it('should not serialize properties starting with $', function() {
expect(toJson({$few: 'v', $$some:'value'}, false)).toEqual('{}');
it('should not serialize properties starting with $$', function() {
expect(toJson({$$some:'value'}, false)).toEqual('{}');
});
it('should serialize properties starting with $', function() {
expect(toJson({$few: 'v'}, false)).toEqual('{"$few":"v"}');
});

4 comments on commit c054288

@ashutoshparmarQT

This comment has been minimized.

Show comment
Hide comment
@ashutoshparmarQT

ashutoshparmarQT Dec 4, 2015

Hello
Since this commit allows to serialize properties which starts with $ but due to this we are facing some issue while submitted for data is binded on server Web.Api.
Before this in angularJs 1.2 it was working fine.

Hello
Since this commit allows to serialize properties which starts with $ but due to this we are facing some issue while submitted for data is binded on server Web.Api.
Before this in angularJs 1.2 it was working fine.

@gkalpak

This comment has been minimized.

Show comment
Hide comment
@gkalpak

gkalpak Dec 7, 2015

Member

@ashutoshparmarQT, this is a documented breaking change between v1.2.x and v1.3.x.
Sorry, if this is inconvenient, but if you need the v.1.2.x behaviour you will have to strip those properties manually.

BTW, this is documented in the 1.2 to 1.3 migration section of the Developer Guide (although the description needs to be improved).

Member

gkalpak replied Dec 7, 2015

@ashutoshparmarQT, this is a documented breaking change between v1.2.x and v1.3.x.
Sorry, if this is inconvenient, but if you need the v.1.2.x behaviour you will have to strip those properties manually.

BTW, this is documented in the 1.2 to 1.3 migration section of the Developer Guide (although the description needs to be improved).

@ashutoshparmarQT

This comment has been minimized.

Show comment
Hide comment
@gkalpak

This comment has been minimized.

Show comment
Hide comment
@gkalpak

gkalpak Dec 8, 2015

Member

FYI, I added a more clear explanation (b0e7d54), so hopefully people won't be caught off-guard in the future 😃

Member

gkalpak replied Dec 8, 2015

FYI, I added a more clear explanation (b0e7d54), so hopefully people won't be caught off-guard in the future 😃

Please sign in to comment.