You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* Prepare the metric result for JSON serialization.
*
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
$target = max(0.0, -66.0); // Replaced with test values to demonstrate
return [
'value' => $this->resolveTransformedValue($this->value),
'target' => $this->resolveTransformedValue($target),
'percentage' => $target !== 0 ? round(($this->value / $target) * 100, $this->roundingPrecision, $this->roundingMode) : 0,
'prefix' => $this->prefix,
'suffix' => $this->suffix,
'suffixInflection' => $this->suffixInflection,
'format' => $this->format,
'avoid' => $this->avoid,
];
}
Description:
If $this->value is float 0.0 and $this->target is <0 then $target is assigned 0.0 which means $target !== 0 passes and we get a division by 0 error.
I know it's a stupid scenario, I'll update my code to not send a negative target. However, might be worth using a loose comparison or floatval as the Progress metric does support floats.
Detailed steps to reproduce the issue on a fresh Nova installation:
Use a progress metric with a value of 0.0 and a target below 0.
The text was updated successfully, but these errors were encountered:
vendor/laravel/nova/src/Metrics/ProgressResult.php@L166
Description:
If
$this->value
is float0.0
and$this->target
is<0
then$target
is assigned0.0
which means$target !== 0
passes and we get a division by 0 error.I know it's a stupid scenario, I'll update my code to not send a negative target. However, might be worth using a loose comparison or
floatval
as the Progress metric does support floats.Detailed steps to reproduce the issue on a fresh Nova installation:
Use a progress metric with a value of 0.0 and a target below 0.
The text was updated successfully, but these errors were encountered: