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

Commit 9a616ea

Browse files
committed
refactor(toJson): remove breaking change from previous CL
Closes #10297
1 parent 7daf4e0 commit 9a616ea

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Angular.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,10 @@ function toJsonReplacer(key, value) {
970970
*/
971971
function toJson(obj, pretty) {
972972
if (typeof obj === 'undefined') return undefined;
973-
return JSON.stringify(obj, toJsonReplacer, pretty === true ? 2 : pretty);
973+
if (!isNumber(pretty)) {
974+
pretty = pretty ? 2 : null;
975+
}
976+
return JSON.stringify(obj, toJsonReplacer, pretty);
974977
}
975978

976979

test/AngularSpec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ describe('angular', function() {
11891189
});
11901190

11911191

1192-
iit('should format objects pretty', function() {
1192+
it('should format objects pretty', function() {
11931193
expect(toJson({a: 1, b: 2}, true)).
11941194
toBe('{\n "a": 1,\n "b": 2\n}');
11951195
expect(toJson({a: {b: 2}}, true)).
@@ -1200,6 +1200,8 @@ describe('angular', function() {
12001200
toBe('{"a":1,"b":2}');
12011201
expect(toJson({a: 1, b: 2}, 1)).
12021202
toBe('{\n "a": 1,\n "b": 2\n}');
1203+
expect(toJson({a: 1, b: 2}, {})).
1204+
toBe('{\n "a": 1,\n "b": 2\n}');
12031205
});
12041206

12051207

0 commit comments

Comments
 (0)