Skip to content

Commit

Permalink
Making sure path is passed to censor when there is only a top level key.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malin authored and Alex Malin committed Oct 4, 2020
1 parent cc179cb commit bc587c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function () {
}

const resetChildingsFormatter = bindings => bindings
function child (bindings) {
function child (bindings, ...args) {
if (!bindings) {
throw Error('missing bindings for child Pino')
}
Expand Down
7 changes: 4 additions & 3 deletions lib/redaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ function redaction (opts, serialize) {
[redactFmtSym]: fastRedact({ paths, censor, serialize, strict })
}

const topCensor = (...args) =>
typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor)
const topCensor = (...args) => {
return typeof censor === 'function' ? serialize(censor(...args)) : serialize(censor)
}

return [...Object.keys(shape), ...Object.getOwnPropertySymbols(shape)].reduce((o, k) => {
// top level key:
if (shape[k] === null) {
o[k] = topCensor
o[k] = (value) => topCensor(value, [k])
} else {
const wrappedCensor = typeof censor === 'function' ? (value, path) => {
return censor(value, [k, ...path])
Expand Down
10 changes: 10 additions & 0 deletions test/redact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ test('redact.censor option – sets the redact value', async ({ is }) => {
})

test('redact.censor option – can be a function that accepts value and path arguments', async ({ is }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['topLevel'], censor: (value, path) => value + ' ' + path.join('.') } }, stream)
instance.info({
topLevel: 'test'
})
const { topLevel } = await once(stream, 'data')
is(topLevel, 'test topLevel')
})

test('redact.censor option – can be a function that accepts value and path arguments (nested path)', async ({ is }) => {
const stream = sink()
const instance = pino({ redact: { paths: ['req.headers.cookie'], censor: (value, path) => value + ' ' + path.join('.') } }, stream)
instance.info({
Expand Down

0 comments on commit bc587c0

Please sign in to comment.