Skip to content

Commit 48c76e7

Browse files
posvayyx990803
authored andcommitted
Fix json filter call with 0 as a parameter (#2890)
Fix #2888
1 parent 8d2cf7d commit 48c76e7

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/filters/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
read: function (value, indent) {
2020
return typeof value === 'string'
2121
? value
22-
: JSON.stringify(value, null, Number(indent) || 2)
22+
: JSON.stringify(value, null, arguments.length > 1 ? indent : 2)
2323
},
2424
write: function (value) {
2525
try {

test/unit/specs/filters/filters_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('Filters', function () {
66
var obj = {a: {b: 2}}
77
expect(filter(obj)).toBe(JSON.stringify(obj, null, 2))
88
expect(filter(obj, 4)).toBe(JSON.stringify(obj, null, 4))
9+
expect(filter(obj, 0)).toBe(JSON.stringify(obj, null, 0))
910
// plain string
1011
expect(filter('1234')).toBe('1234')
1112
})

0 commit comments

Comments
 (0)