Skip to content

Path pattern *[*].samples.*.runId doesn't work correctly for nested arrays #25

@thienscmon

Description

@thienscmon

First, thank you for your work on this library! We're actively trying to migrate from fast-redact to @pinojs/redact because of the competitive performance improvements your library offers. However, we've encountered an issue with a specific path pattern that's blocking our migration.

Description

The path pattern ["*[*].samples.*.runId"] doesn't work correctly in @pinojs/redact but works as expected in fast-redact. This pattern should redact runId fields in samples arrays at any nesting level, including within other arrays.

Expected Behavior

The pattern ["*[*].samples.*.runId"] should redact all runId properties within samples arrays, regardless of where they appear in the nested structure (at root level, inside objects, or inside other arrays).

Actual Behavior

When using @pinojs/redact, the redaction doesn't work correctly for this path pattern, while fast-redact handles it properly.

Reproduction

import redactModule from "@pinojs/redact";
// import redactModule from "fast-redact"; // This works correctly

const redact = redactModule({
  paths: ["*[*].samples.*.runId"],
  serialize: false,
  censor: undefined, // with `fast-redact`
  // OR
  remove: true, // with `@pinojs/redact`
});

const samples = [
  {
    runId: 2,
    a: "123",
  },
];

const result = redact({
  samples: samples,
  a: {
    b: {
      c: {
        samples: samples,
      },
      array: [
        {
          samples: samples,
        },
      ],
    },
  },
  rows: [
    {
      samples: samples,
      array: [
        {
          samples: samples,
        },
      ],
    },
  ],
});

console.log(JSON.stringify(result, null, 2));

pinojs/redact Output

{
  "samples": [
    {
      "runId": 2,
      "a": "123"
    }
  ],
  "a": {
    "b": {
      "c": {
        "samples": [
          {
            "runId": 2,
            "a": "123"
          }
        ]
      },
      "array": [
        {
          "samples": [
            {
              "runId": 2,
              "a": "123"
            }
          ]
        }
      ]
    }
  },
  "rows": [
    {
      "samples": [
        {
          "a": "123"
        }
      ],
      "array": [
        {
          "samples": [
            {
              "runId": 2,
              "a": "123"
            }
          ]
        }
      ]
    }
  ]
}

Expected Output (fast-redact)

{
  "samples": [
    {
      "a": "123"
    }
  ],
  "a": {
    "b": {
      "c": {
        "samples": [
          {
            "a": "123"
          }
        ]
      },
      "array": [
        {
          "samples": [
            {
              "a": "123"
            }
          ]
        }
      ]
    }
  },
  "rows": [
    {
      "samples": [
        {
          "a": "123"
        }
      ],
      "array": [
        {
          "samples": [
            {
              "a": "123"
            }
          ]
        }
      ]
    }
  ]
}

Notice that runId is removed from all samples arrays at every nesting level.

Environment

  • @pinojs/redact: [0.4.0]
  • fast-redact: [3.5.0] (works correctly)
  • Node.js: [22.20.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions