mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 19:40:56 +08:00
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.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"}');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user