Skip to content

Commit

Permalink
Fix precensored restore (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehedger authored Aug 28, 2021
1 parent f3135e4 commit d562319
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/restorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function restorer ({ secret, wcLen }) {
return function compileRestore () {
if (this.restore) return
const paths = Object.keys(secret)
.filter((path) => secret[path].precensored === false)
const resetters = resetTmpl(secret, paths)
const hasWildcards = wcLen > 0
const state = hasWildcards ? { secret, groupRestore, nestedRestore } : { secret }
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,22 @@ test('redact.restore function places original values back in place', ({ end, is
end()
})

test('redact.restore function places original values back in place when called twice and the first call is precensored', ({ end, is }) => {
const censor = 'test'
const redact = fastRedact({ paths: ['a'], censor, serialize: false })
const o1 = { a: censor }
const o2 = { a: 'a' }
redact(o1)
is(o1.a, censor)
redact.restore(o1)
is(o1.a, censor)
redact(o2)
is(o2.a, censor)
redact.restore(o2)
is(o2.a, 'a')
end()
})

test('masks according to supplied censor function', ({ end, is }) => {
const redact = fastRedact({ paths: ['a'], censor: censorFct, serialize: false })
is(redact({ a: '0123456' }).a, 'xxx56')
Expand Down

0 comments on commit d562319

Please sign in to comment.