davidmarkclements / fast-redact

very fast object redaction
MIT License
278 stars 30 forks source link

Redact fails when both the parent and child nodes are redacted #66

Open jonathansamines opened 8 months ago

jonathansamines commented 8 months ago

The following redaction pattern works on v3.1.2 and v3.2.0 but not on v3.3.0:

'use strict';

const fastRedact = require('fast-redact');

const thing = {
  prop: {
    top: {
      secret: 'top secret',
    },
  },
};

const redact = fastRedact({
  paths: ['*.*.secret', '*.top'],
  censor: '**SECRET**',
});

console.log(redact(thing));

On v3.3.0 it fails with the following error:

/Users/user/project/node_modules/fast-redact/lib/modifiers.js:54
    current[path[0]] = value
                     ^

TypeError: Cannot create property 'secret' on string '**SECRET**'
    at Object.nestedRestore (/Users/user/project/node_modules/fast-redact/lib/modifiers.js:54:22)
    at Object.eval (eval at compileRestore (/Users/user/project/node_modules/fast-redact/lib/restorer.js:15:20), <anonymous>:12:17)
    at Object.eval (eval at redactor (/Users/user/project/node_modules/fast-redact/lib/redactor.js:9:18), <anonymous>:24:10)
    at Object.<anonymous> (/Users/user/project/test.js:18:13)

The conditions to generate this failure seem to be:

Would appreciate some help to understand whether this is working as designed, a bug or known limitation.