From 6b3b05558f727284fad827d1d2bdcb50c057c2e7 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 19 Jul 2019 22:34:34 +0100 Subject: [PATCH] API: Fix 'user_id' field of ApiCSPReport Was accidentally turned into an always-true boolean in 5f343617, due to confusion with JavaScript's default '||' operator. Change-Id: I24071e22f8bb7a296ae138303f63acdb8ea4950a --- includes/api/ApiCSPReport.php | 2 +- tests/phpunit/includes/api/ApiCSPReportTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiCSPReport.php b/includes/api/ApiCSPReport.php index f53d2b93c2..be2da34280 100644 --- a/includes/api/ApiCSPReport.php +++ b/includes/api/ApiCSPReport.php @@ -54,7 +54,7 @@ class ApiCSPReport extends ApiBase { // XXX Is it ok to put untrusted data into log?? 'csp-report' => $report, 'method' => __METHOD__, - 'user_id' => $this->getUser()->getId() || 'logged-out', + 'user_id' => $this->getUser()->getId() ?: 'logged-out', 'user-agent' => $userAgent, 'source' => $this->getParameter( 'source' ), ] ); diff --git a/tests/phpunit/includes/api/ApiCSPReportTest.php b/tests/phpunit/includes/api/ApiCSPReportTest.php index dab9d3f0f7..b3e0543c78 100644 --- a/tests/phpunit/includes/api/ApiCSPReportTest.php +++ b/tests/phpunit/includes/api/ApiCSPReportTest.php @@ -39,8 +39,7 @@ class ApiCSPReportTest extends MediaWikiIntegrationTestCase { ' blocked from being loaded on :4', [ 'method' => 'ApiCSPReport::execute', - // FIXME - 'user_id' => true, + 'user_id' => 'logged-out', 'user-agent' => 'Test/0.0', 'source' => 'internal' ] -- 2.20.1