Skip to content

Commit

Permalink
correct interpolation safety behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarkclements committed Jun 2, 2018
1 parent 5a999f9 commit e926df7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function pino (opts, stream) {

// internal options
iopts.stringify = iopts.safe ? stringifySafe : JSON.stringify
iopts.formatOpts = {lowres: true}
iopts.formatOpts = {lowres: !iopts.safe}
iopts.messageKeyString = `,"${iopts.messageKey}":`
iopts.end = ',"v":' + LOG_VERSION + '}' + (iopts.crlf ? '\r\n' : '\n')
iopts.cache = !iopts.extreme ? null : {
Expand Down
22 changes: 22 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,25 @@ test('when safe is true it should ONLY use `fast-safe-stringify`', function (t)
})
t.end()
})

test('when safe is true, fast-safe-stringify must be used when interpolating', function (t) {
var instance = pino({safe: true}, sink(function (chunk, enc, cb) {
const { msg } = chunk
t.is(msg, 'test {"a":{"b":{"c":"[Circular]"}}}')
t.end()
}))
var o = { a: { b: {} } }
o.a.b.c = o.a.b
instance.info('test', o)
})

test('when safe is false, interpolation output circulars at the root', function (t) {
var instance = pino({safe: false}, sink(function (chunk, enc, cb) {
const { msg } = chunk
t.is(msg, 'test "[Circular]"')
t.end()
}))
var o = { a: { b: {} } }
o.a.b.c = o.a.b
instance.info('test', o)
})

0 comments on commit e926df7

Please sign in to comment.