Skip to content

Conversation

@yanyi-wego
Copy link
Contributor

Context

This PR adds support for masking arrays containing string values using the ["property", "[]"] pattern in the logger's JSON masking functionality. Previously, the masking system only supported patterns like ["[]", "property"] but not the reverse where the array key comes at the end.

Approach

The implementation adds support for the ["property", "[]"] pattern through several key changes:

  1. Extended maskArrayRecursive to handle the new pattern by detecting when array key ("[]") appears at the end of the key path
  2. Refactored for readability by extracting the large switch statement into focused single-responsibility functions with descriptive names and proper godoc comments
  3. Simplified array masking logic by consolidating duplicate functionality between maskArrayContents and maskAllStringValues
  4. Added comprehensive test coverage for the new functionality

The new pattern enables masking arrays like ["some value", "another value"] when using keys ["test7", "[]"], making the masking system more flexible and intuitive.

Testing

All existing tests pass, and new test cases have been added to verify the array string masking functionality works correctly with both single and multiple string values in arrays.

Enable masking arrays containing string values using the pattern
["property", "[]"].

Refactor maskArrayRecursive to use switch statement for better
readability and add maskAllStringValues helper function.
Extract switch case logic into focused single-responsibility
functions with descriptive names and godoc comments. Replace
complex boolean conditions with self-documenting variables.

Improves maintainability by separating concerns and making each
function handle one specific JSON key pattern.
Remove maskArrayContents function which duplicated logic in
maskAllStringValues. Simplify maskAllStringValues to only mask
strings and ignore non-string items rather than recursively
processing nested arrays.

This eliminates unnecessary complexity since the ["property", "[]"]
pattern should only mask strings within the target array.
@yanyi-wego yanyi-wego marked this pull request as ready for review September 29, 2025 08:10
@yanyi-wego yanyi-wego merged commit 6ddf13d into main Sep 29, 2025
2 checks passed
@yanyi-wego yanyi-wego deleted the update-logger-masking-array-of-strings branch September 29, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants