MonitoredObject: Keep structure of nested cvs during protection

fixes #4439
This commit is contained in:
Johannes Meyer 2021-07-13 17:43:17 +02:00
parent 2b09d22326
commit d123b390b1
1 changed files with 10 additions and 7 deletions

View File

@ -466,19 +466,22 @@ abstract class MonitoredObject implements Filterable
return $customvars; return $customvars;
} }
$obfuscatedCustomVars = []; $obfuscator = function ($vars) use ($blacklistPattern, &$obfuscator) {
$obfuscator = function ($vars) use ($blacklistPattern, &$obfuscatedCustomVars, &$obfuscator) { $result = [];
foreach ($vars as $name => $value) { foreach ($vars as $name => $value) {
if ($blacklistPattern && preg_match($blacklistPattern, $name)) { if ($blacklistPattern && preg_match($blacklistPattern, $name)) {
$obfuscatedCustomVars[$name] = '***'; $result[$name] = '***';
} elseif ($value instanceof stdClass || is_array($value)) {
$obfuscated = $obfuscator($value);
$result[$name] = $value instanceof stdClass ? (object) $obfuscated : $obfuscated;
} else { } else {
$obfuscatedCustomVars[$name] = $value instanceof stdClass || is_array($value) $result[$name] = $value;
? $obfuscator($value)
: $value;
} }
} }
return $result;
}; };
$obfuscator($customvars); $obfuscatedCustomVars = $obfuscator($customvars);
return $customvars instanceof stdClass ? (object) $obfuscatedCustomVars : $obfuscatedCustomVars; return $customvars instanceof stdClass ? (object) $obfuscatedCustomVars : $obfuscatedCustomVars;
} }