MDL-84879 core: Remove stacktrace args from exceptions

This commit is contained in:
Andrew Nicols 2025-03-14 17:16:00 +08:00 committed by Jun Pataleta
parent a2374ee968
commit 41917db65e
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
3 changed files with 9 additions and 1 deletions

View File

@ -123,7 +123,10 @@ abstract class exception_response extends \core\router\schema\response\response
): array {
$data = [
'message' => $exception->getMessage(),
'stacktrace' => $exception->getTrace(),
'stacktrace' => array_map(
fn ($frame): array => array_filter($frame, fn ($key) => $key !== 'args', ARRAY_FILTER_USE_KEY),
$exception->getTrace(),
),
];
if (is_a($exception, \moodle_exception::class)) {

View File

@ -769,9 +769,11 @@ if (!isset($CFG->debugdisplay)) {
// Some parts of Moodle cannot display errors and debug at all.
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('zend.exception_ignore_args', '1');
} else if (empty($CFG->debugdisplay)) {
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('zend.exception_ignore_args', '1');
} else {
// This is very problematic in XHTML strict mode!
ini_set('display_errors', '1');

View File

@ -425,6 +425,9 @@ abstract class route_testcase extends \advanced_testcase {
$payload = $this->decode_response($response);
$this->assertObjectHasProperty('message', $payload);
$this->assertObjectHasProperty('stacktrace', $payload);
foreach ($payload->stacktrace as $frame) {
$this->assertObjectNotHasProperty('args', $frame);
}
}
/**