davidmarkclements / fast-redact

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

Value of object in nested array gets overwritten to the array last index value #52

Open hermawan-hadi opened 2 years ago

hermawan-hadi commented 2 years ago

When providing path that has nested array, value of all redacted keys in the array gets overwritten to the value of the array's last index object value.

const fastRedact = require("fast-redact");
const redact = fastRedact({
  paths: ["a[*].b[*].c"],
});

const obj = {
  a: [{ b: [{ c: 1 }, { c: 2 }, { c: 3 }] }],
};

console.log(redact(obj));
console.log(inspect(obj, undefined, null));

Output

{"a":[{"b":[{"c":"[REDACTED]"},{"c":"[REDACTED]"},{"c":"[REDACTED]"}]}]}
{
  a: [
    { b: [ { c: 3 }, { c: 3 }, { c: 3 } ] }
  ]
}

Expected result of c should be retained as 1, 2, 3 respectively.

mcollina commented 2 years ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.