Skip to content

Commit

Permalink
masking edge cases fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gaubansa committed Jun 14, 2022
1 parent 52d293e commit cdd7377
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ public string MaskSensitiveData(string str)
{
foreach (KeyValuePair<string, string> tag in sensitiveTags)
{
//removing the space and hypen from PAN details before masking
if (tag.Key.StartsWith("\\\"number\\\"") || tag.Key.StartsWith("\\\"cardNumber\\\"") || tag.Key.StartsWith("\\\"account\\\"")
|| tag.Key.StartsWith("\\\"prefix\\\"") || tag.Key.StartsWith("\\\"bin\\\""))
{
string[] splittedStr = tag.Key.Split(':');
string tagName = splittedStr[0];
string specialPatternForPAN = "(((\\s*[s/-]*\\s*)+)\\p{N}((\\s*[s/-]*\\s*)+))+";

// match the patters for PAN number
MatchCollection matches = Regex.Matches(str, $"{tagName}:\\\"{specialPatternForPAN}\\\"");

//remove space and dash from the all matched pattern
foreach (Match match in matches)
{
String strr = match.ToString();
strr = Regex.Replace(strr, "\\s*[s/-]*", "");

//replace original value in str with match
str = str.Replace(match.ToString(), strr);
}
}
str = Regex.Replace(str, tag.Key, tag.Value);
}
}
Expand Down

0 comments on commit cdd7377

Please sign in to comment.