@@ -317,7 +317,7 @@ protected function collectVars(Throwable $exception, int $statusCode): array
317317 $ trace = $ exception ->getTrace ();
318318
319319 if ($ this ->config ->sensitiveDataInTrace !== []) {
320- $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
320+ $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
321321 }
322322
323323 return [
@@ -336,32 +336,53 @@ protected function collectVars(Throwable $exception, int $statusCode): array
336336 *
337337 * @param array|object $trace
338338 *
339+ * @return array|object
340+ *
339341 * @deprecated No longer used. Moved to BaseExceptionHandler.
340342 */
341- protected function maskSensitiveData (&$ trace , array $ keysToMask , string $ path = '' )
343+ protected function maskSensitiveData ($ trace , array $ keysToMask , string $ path = '' )
344+ {
345+ foreach ($ trace as $ i => $ line ) {
346+ $ trace [$ i ]['args ' ] = $ this ->maskData ($ line ['args ' ], $ keysToMask );
347+ }
348+
349+ return $ trace ;
350+ }
351+
352+ /**
353+ * @param array|object $args
354+ *
355+ * @return array|object
356+ */
357+ private function maskData ($ args , array $ keysToMask , string $ path = '' )
342358 {
343359 foreach ($ keysToMask as $ keyToMask ) {
344360 $ explode = explode ('/ ' , $ keyToMask );
345361 $ index = end ($ explode );
346362
347363 if (strpos (strrev ($ path . '/ ' . $ index ), strrev ($ keyToMask )) === 0 ) {
348- if (is_array ($ trace ) && array_key_exists ($ index , $ trace )) {
349- $ trace [$ index ] = '****************** ' ;
350- } elseif (is_object ($ trace ) && property_exists ($ trace , $ index ) && isset ($ trace ->{$ index })) {
351- $ trace ->{$ index } = '****************** ' ;
364+ if (is_array ($ args ) && array_key_exists ($ index , $ args )) {
365+ $ args [$ index ] = '****************** ' ;
366+ } elseif (
367+ is_object ($ args ) && property_exists ($ args , $ index )
368+ && isset ($ args ->{$ index }) && is_scalar ($ args ->{$ index })
369+ ) {
370+ $ args ->{$ index } = '****************** ' ;
352371 }
353372 }
354373 }
355374
356- if (is_object ( $ trace )) {
357- $ trace = get_object_vars ( $ trace );
358- }
359-
360- if ( is_array ( $ trace )) {
361- foreach ($ trace as $ pathKey => $ subarray ) {
362- $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
375+ if (is_array ( $ args )) {
376+ foreach ( $ args as $ pathKey => $ subarray ) {
377+ $ args [ $ pathKey ] = $ this -> maskData ( $ subarray , $ keysToMask , $ path . ' / ' . $ pathKey );
378+ }
379+ } elseif ( is_object ( $ args )) {
380+ foreach ($ args as $ pathKey => $ subarray ) {
381+ $ args ->{ $ pathKey } = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
363382 }
364383 }
384+
385+ return $ args ;
365386 }
366387
367388 /**
0 commit comments