Skip to content

Commit 1ea19cb

Browse files
Jiaming Youmeta-codesync[bot]
authored andcommitted
CAPI ParamBuilder][PII][php][84/n] Return value as is if already normalized and hashed by param builder
Summary: Return value as is if already normalized and hashed by param builder Differential Revision: D85123313 fbshipit-source-id: e152757ec450151afd8a120f36d30f9039ed2ab9
1 parent 93e67bc commit 1ea19cb

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

php/capi-param-builder/src/piiUtil/PIIUtils.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ public static function getNormalizedAndHashedPII($piiValue, $dataType)
7272
return null;
7373
}
7474

75-
if (SharedUtils::looksLikeHashed($piiValue)) {
76-
return mb_strtolower($piiValue) . '.' .
75+
if (SharedUtils::looksLikeHashed(trim($piiValue))) {
76+
return mb_strtolower(trim($piiValue)) . '.' .
7777
AppendixProvider::getAppendix(false);
78+
} else if (
79+
PIIUtils::isAlreadyNormalizedAndHashedByParamBuilder(trim($piiValue))
80+
) {
81+
return trim($piiValue);
7882
} else {
7983
$normalizedPII = PIIUtils::getNormalizedPII($piiValue, $dataType);
8084
if ($normalizedPII === null || $normalizedPII === '') {
@@ -84,4 +88,20 @@ public static function getNormalizedAndHashedPII($piiValue, $dataType)
8488
AppendixProvider::getAppendix(true);
8589
}
8690
}
91+
92+
private static function isAlreadyNormalizedAndHashedByParamBuilder($input)
93+
{
94+
// Find the position of the last dot
95+
$lastDot = strrpos($input, '.');
96+
if ($lastDot !== false) {
97+
$suffix = substr($input, $lastDot + 1);
98+
if (
99+
in_array($suffix, SUPPORTED_LANGUAGES_TOKEN, true) ||
100+
mb_strlen($suffix) == APPENDIX_LENGTH_V2
101+
) {
102+
return SharedUtils::looksLikeHashed(substr($input, 0, $lastDot));
103+
}
104+
}
105+
return false;
106+
}
87107
}

0 commit comments

Comments
 (0)