davidmarkclements / fast-redact

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

How to specify path containing lower level '-' character #54

Closed steve-baldwin closed 1 year ago

steve-baldwin commented 1 year ago

If I have a structure:

{
  headers: {
    host: "xxx",
    "user-agent": "xxx",
    "x-authorization": "xxx"
  }
}

How do I specify a path that redacts headers.x-authorization ?

Here's a test script I was using for something similar:

import * as F from 'fast-redact';
import { inspect } from 'util';

describe('Redact', () => {
    it('can redact', () => {
        const options: F.RedactOptions = {
            paths: ['authorization', 'abc."x-authorization"'],
            serialize: false
        };
        const original = {
            innocuous: 'public info',
            authorization: 'secret info',
            abc: {
                'x-authorization': 'another secret'
            }
        };
        const r = F(options);
        r(original);
        console.log(inspect(original, { depth: null }));
        expect(original.authorization).toEqual('[REDACTED]');
    });
});

I get:

    fast-redact – Invalid path (abc."x-authorization")

      15 |             }
      16 |         };
    > 17 |         const r = F(options);
         |                   ^

I tried other options - e.g. 'abc.x-authorization', but I couldn't come up with anything that worked.

steve-baldwin commented 1 year ago

Never mind. I was able to get the test script above working with:

            paths: ['authorization', 'abc["x-authorization"]'],

Makes sense when you think about it 😄 .