From 29ae19b2617c89e487998a160f6c2a9fff5b66e1 Mon Sep 17 00:00:00 2001 From: Andrew Downes <mrdownes@hotmail.com> Date: Fri, 21 Dec 2018 15:34:30 +0000 Subject: [PATCH] fix: Avoids sending invalid JSON to the LRS. (#364) --- src/loader/lrs.php | 4 ++++ src/loader/moodle_curl_lrs.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/loader/lrs.php b/src/loader/lrs.php index 5eff8fd..b79516a 100644 --- a/src/loader/lrs.php +++ b/src/loader/lrs.php @@ -29,6 +29,10 @@ function load(array $config, array $events) { $auth = base64_encode($username.':'.$password); $postdata = json_encode($statements); + if ($postdata === false) { + throw new \Exception('JSON encode error: '.json_last_error_msg()); + } + $request = curl_init(); curl_setopt($request, CURLOPT_URL, $url); curl_setopt($request, CURLOPT_POSTFIELDS, $postdata); diff --git a/src/loader/moodle_curl_lrs.php b/src/loader/moodle_curl_lrs.php index f559c9c..278f2ee 100644 --- a/src/loader/moodle_curl_lrs.php +++ b/src/loader/moodle_curl_lrs.php @@ -35,6 +35,10 @@ function load(array $config, array $events) { $auth = base64_encode($username.':'.$password); $postdata = json_encode($statements); + if ($postdata === false) { + throw new \Exception('JSON encode error: '.json_last_error_msg()); + } + $request = new \curl(); $responsetext = $request->post($url, $postdata, [ 'CURLOPT_HTTPHEADER' => [ -- GitLab