Skip to content

Add support for prefix and suffix preservation in FixedLengthMasker#9

Merged
ehayik merged 1 commit intomasterfrom
feat/preserved-sections
Jun 8, 2025
Merged

Add support for prefix and suffix preservation in FixedLengthMasker#9
ehayik merged 1 commit intomasterfrom
feat/preserved-sections

Conversation

@ehayik
Copy link
Owner

@ehayik ehayik commented Jun 8, 2025

Why

To add support for preserving prefix and suffix sections during masking.

var masker = Masker.fixedLength(4)
    .preserveSuffix(3)  // Keep last 3 characters unmasked
    .preservePrefix(2)  // Keep first 2 characters unmasked
    .build();

var ssn = "123-45-6789";
var maskedSsn = masker.apply(ssn);
// Result: "12******789"

How

  • Added prefixLength and suffixLength fields for preserving sections of the string during masking.
  • Updated constructor and builder pattern to allow configuration of the new fields.
  • Added a new private method applyWithSuffixAndPrefixPreservation to handle the logic for prefix and suffix preservation during masking.
  • Added parameterized tests with various prefix and suffix preservation scenarios.

…sker

Introduced the ability to preserve prefix and suffix sections when applying fixed-length masking. Updated builder methods and logic to configure these preservation lengths. Added tests to ensure correctness of the new behavior.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 8, 2025

@ehayik ehayik self-assigned this Jun 8, 2025
@ehayik ehayik added this to the v1.1.0 milestone Jun 8, 2025
@ehayik ehayik added the enhancement New feature or request label Jun 8, 2025
@ehayik ehayik linked an issue Jun 8, 2025 that may be closed by this pull request
@ehayik ehayik merged commit 01f861e into master Jun 8, 2025
2 checks passed
@ehayik ehayik deleted the feat/preserved-sections branch June 20, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add preserved sections configuration in fixed-length masker

1 participant