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

Commit c054288

Browse files
rodyhaddadbtford
authored andcommitted
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.
1 parent 8c02a49 commit c054288

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Angular.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ function bind(self, fn) {
975975
function toJsonReplacer(key, value) {
976976
var val = value;
977977

978-
if (typeof key === 'string' && key.charAt(0) === '$') {
978+
if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
979979
val = undefined;
980980
} else if (isWindow(value)) {
981981
val = '$WINDOW';
@@ -996,7 +996,7 @@ function toJsonReplacer(key, value) {
996996
* @function
997997
*
998998
* @description
999-
* Serializes input into a JSON-formatted string. Properties with leading $ characters will be
999+
* Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
10001000
* stripped since angular uses this notation internally.
10011001
*
10021002
* @param {Object|Array|Date|string|number} obj Input to be serialized into JSON.

test/AngularSpec.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1131,8 +1131,13 @@ describe('angular', function() {
11311131
});
11321132

11331133

1134-
it('should not serialize properties starting with $', function() {
1135-
expect(toJson({$few: 'v', $$some:'value'}, false)).toEqual('{}');
1134+
it('should not serialize properties starting with $$', function() {
1135+
expect(toJson({$$some:'value'}, false)).toEqual('{}');
1136+
});
1137+
1138+
1139+
it('should serialize properties starting with $', function() {
1140+
expect(toJson({$few: 'v'}, false)).toEqual('{"$few":"v"}');
11361141
});
11371142

11381143

0 commit comments

Comments
 (0)