Skip to content

Commit

Permalink
fix(redaction): remove undefined entries for removed number and boole…
Browse files Browse the repository at this point in the history
…an values (#756)
  • Loading branch information
tuckbick authored and mcollina committed Jan 8, 2020
1 parent 7538351 commit e39774e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/tools.js
Expand Up @@ -105,8 +105,7 @@ function asJson (obj, num, time) {
// this case explicity falls through to the next one
case 'boolean':
if (stringifier) value = stringifier(value)
data += ',"' + key + '":' + value
continue
break
case 'string':
value = (stringifier || asString)(value)
break
Expand Down
22 changes: 21 additions & 1 deletion test/redact.test.js
Expand Up @@ -240,7 +240,7 @@ test('redact.remove option – removes both key and value', async ({ is }) => {
is('cookie' in req.headers, false)
})

test('redact.remove – top level key', async ({ is }) => {
test('redact.remove – top level key - object value', async ({ is }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
instance.info({
Expand All @@ -250,6 +250,26 @@ test('redact.remove – top level key', async ({ is }) => {
is('key' in o, false)
})

test('redact.remove – top level key - number value', async ({ is }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
instance.info({
key: 1
})
const o = await once(stream, 'data')
is('key' in o, false)
})

test('redact.remove – top level key - boolean value', async ({ is }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['key'], remove: true } }, stream)
instance.info({
key: false
})
const o = await once(stream, 'data')
is('key' in o, false)
})

test('redact.remove – top level key in child logger', async ({ is }) => {
const stream = sink()
const opts = { redact: { paths: ['key'], remove: true } }
Expand Down

0 comments on commit e39774e

Please sign in to comment.