Skip to content

Commit 1f0ee4b

Browse files
committed
Modified ANetSensitiveFields.php
1 parent 587ab58 commit 1f0ee4b

2 files changed

Lines changed: 37 additions & 28 deletions

File tree

lib/net/authorize/util/ANetSensitiveFields.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,32 @@ private static function getDefaulSensitiveXmlTags(){
1313
// );
1414
return array( //format for each element: array(tag name, regex-pattern, regex-replacement)
1515
new SensitiveTag("cardCode"),
16-
new SensitiveTag("cardNumber","([^0-9]*)(\d+)(\d{4})(.*)","$1xxxx-$3$4",false),
16+
new SensitiveTag("cardNumber","(\d+)(\d{4})","$1xxxx-$3$4",false),
1717
new SensitiveTag("expirationDate")
1818
);
1919
}
2020
public static function getSensitiveXmlTags(){
2121
$sensitiveTags = array();
2222
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
23-
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
24-
if (file_exists($userConfigFilePath)) { //client config for tags
23+
$userConfigFile = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
24+
$presentUserConfigFile = file_exists($userConfigFile);
25+
if ($presentUserConfigFile) { //client config for tags
2526
//read list of tags(and associate regex-patterns and replacements) from .json file
26-
$sensitiveTags = json_decode(file_get_contents($configFilePath));
27+
$jsonFileObejct = json_decode(file_get_contents($userConfigFile));
28+
$sensitiveTags = $jsonFileObejct["sensitiveTags"];
2729
if (json_last_error() === JSON_ERROR_NONE) {// JSON is valid
2830
}
2931
else{
30-
echo "ERROR: Invalid json in: " . $userConfigFilePath . " json_last_error_msg : " . json_last_error_msg();
31-
return self::getDefaulSensitiveXmlTags();
32+
echo "ERROR: Invalid json in: " . $userConfigFile . " json_last_error_msg : " . json_last_error_msg();
33+
$presentUserConfigFile = false;
3234
}
3335
}
34-
else if (file_exists($configFilePath)) { //default sdk config for tags
35-
$sensitiveTags = json_decode(file_get_contents($configFilePath));
36+
if (!$presentUserConfigFile) { //default sdk config for tags
37+
if(!file_exists($configFilePath)){
38+
exit("ERROR: No config file: " . $configFilePath);
39+
}
40+
$jsonFileObejct = json_decode(file_get_contents($configFilePath));
41+
$sensitiveTags = $jsonFileObejct->sensitiveTags;
3642
if (json_last_error() === JSON_ERROR_NONE) {
3743
}
3844
else{
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
[
2-
{
3-
"tagName": "cardCode",
4-
"pattern": "",
5-
"replacement": "",
6-
"disableMask": false
7-
},
8-
{
9-
"tagName": "cardNumber",
10-
"pattern": "(\\d+)(\\d{4})",
11-
"replacement": "xxxx-$2",
12-
"disableMask": false
13-
},
14-
{
15-
"tagName": "expirationDate",
16-
"pattern": "",
17-
"replacement": "",
18-
"disableMask": false
19-
}
20-
]
1+
{
2+
"sensitiveTags": [
3+
{
4+
"tagName": "cardCode",
5+
"pattern": "",
6+
"replacement": "",
7+
"disableMask": false
8+
},
9+
{
10+
"tagName": "cardNumber",
11+
"pattern": "(\\d+)(\\d{4})",
12+
"replacement": "xxxx-$2",
13+
"disableMask": false
14+
},
15+
{
16+
"tagName": "expirationDate",
17+
"pattern": "",
18+
"replacement": "",
19+
"disableMask": false
20+
}
21+
]
22+
}
23+

0 commit comments

Comments
 (0)