Skip to content

Commit 5d3f187

Browse files
Kai SongKai Song
authored andcommitted
switch to use NSrange
1 parent 62bc447 commit 5d3f187

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

IdentityCore/src/logger/MSIDMaskedLogParameter.m

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,26 @@ - (NSString *)EUIIMaskedDescription
112112

113113
- (NSString *)noMaskWithCondition
114114
{
115-
// If input is NSError, mask userinfo as it may contain upn
115+
// If input is NSError, mask upn and email address from if there is any
116116
if ([self.parameterValue isKindOfClass:[NSError class]])
117117
{
118118
NSError *errorParameter = (NSError *)self.parameterValue;
119119
if (errorParameter.userInfo && errorParameter.userInfo.allKeys.count > 0)
120120
{
121-
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}";
122-
NSPredicate *emailPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
123-
BOOL maskedError = NO;
124-
NSMutableDictionary *localUserInfo = [errorParameter.userInfo mutableCopy];
125121
for (NSErrorUserInfoKey key in errorParameter.userInfo)
126122
{
127-
if ([errorParameter.userInfo[key] isKindOfClass:NSString.class])
128-
{
129-
if ([emailPredicate evaluateWithObject:errorParameter.userInfo[key]])
123+
if ([errorParameter.userInfo[key] isKindOfClass:NSString.class]) {
124+
NSString *stringValue = (NSString *)errorParameter.userInfo[key];
125+
NSRange emailIndex = [stringValue rangeOfString:@"@"];
126+
if (emailIndex.location != NSNotFound)
130127
{
131-
localUserInfo[key] = _PII_NULLIFY(errorParameter.userInfo[key]);
132-
maskedError = YES;
128+
NSMutableDictionary *localUserInfo = [errorParameter.userInfo mutableCopy];
129+
// localUserInfo is only for log purpose, so should be safe to assign value here
130+
localUserInfo[key] = _PII_NULLIFY(stringValue);
131+
return [NSString stringWithFormat:@"MaskedError(%@, %ld, %@)", errorParameter.domain, (long)errorParameter.code, localUserInfo];
133132
}
134133
}
135134
}
136-
137-
if (maskedError)
138-
{
139-
return [NSString stringWithFormat:@"MaskedError(%@, %ld, %@)", errorParameter.domain, (long)errorParameter.code, localUserInfo];
140-
}
141135
}
142136
}
143137

0 commit comments

Comments
 (0)