[Console] ProgressBar progressChar wider than one throws "PHP Fatal error: Uncaught ValueError: str_repeat(): Argument #2 ($times) must be greater than or equal to 0" when displaying at the end of the bar
#49111
<?phprequire'vendor/autoload.php';
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$bar = new \Symfony\Component\Console\Helper\ProgressBar($output);
$bar->setProgressCharacter("> ");
$bar->setMaxSteps(100);
$bar->setProgress(99);
Possible Solution
No response
Additional Context
I encountered this error when reproducing the format from the ProgressBarTest->testAnsiColorsAndEmojis() test, and it has a progress character longer than one as well.
This test's progress bar is only o to 15, so I believe it doesn't trigger the error simply because the progress character doesn't get close enough to the end of the bar.
Additionally, what lead me here was because the documentation has this cool progress bar format but no code on how to produce it.
I believe the above mentioned test is an earlier version of this (from 5.3):
The text was updated successfully, but these errors were encountered:
Yeah, one would think it would only be one with how the functions are named. But like I said I was trying to replicate the demo, and the test has more that one.
Symfony version(s) affected
6.2.5
Description
When the
progressChar
is more than one character wide, it causes an error when updating the progress bar at almost the end.This doesn't always trigger, depending on redraw frequency and number of bar steps.
It's caused by this line returning a negative number in certain situations:
symfony/src/Symfony/Component/Console/Helper/ProgressBar.php
Line 510 in 8d58538
How to reproduce
Possible Solution
No response
Additional Context
I encountered this error when reproducing the format from the
ProgressBarTest->testAnsiColorsAndEmojis()
test, and it has a progress character longer than one as well.symfony/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php
Line 923 in 8d58538
This test's progress bar is only o to 15, so I believe it doesn't trigger the error simply because the progress character doesn't get close enough to the end of the bar.
Additionally, what lead me here was because the documentation has this cool progress bar format but no code on how to produce it.
I believe the above mentioned test is an earlier version of this (from 5.3):
The text was updated successfully, but these errors were encountered: