From 5a1aef5a51fc51dcc17312bb7b4e92c61b25dc2c Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 30 Jan 2024 21:45:57 +0000 Subject: [PATCH] MDL-80768 output: stricter progress bar component percentage type. Avoid mixing float/string types, where the decimal separator could vary according to current locale. --- lib/outputcomponents.php | 2 +- lib/outputrenderers.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index d930e4a060c..d568c851b23 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -5191,7 +5191,7 @@ class progress_bar implements renderable, templatable { $this->percent = $percent; $this->lastupdate = microtime(true); - echo $OUTPUT->render_progress_bar_update($this->html_id, sprintf("%.1f", $this->percent), $msg, $estimatemsg); + echo $OUTPUT->render_progress_bar_update($this->html_id, $this->percent, $msg, $estimatemsg); flush(); } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index f90af629345..d4e3b7b1fa5 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -5037,7 +5037,12 @@ EOD; * @return string ascii fragment */ public function render_progress_bar_update(string $id, float $percent, string $msg, string $estimate) : string { - return html_writer::script(js_writer::function_call('updateProgressBar', [$id, $percent, $msg, $estimate])); + return html_writer::script(js_writer::function_call('updateProgressBar', [ + $id, + round($percent, 1), + $msg, + $estimate, + ])); } /** -- 2.43.0