From 894bc74ba4ce9d1cd55c992334f250a2fc6d505e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:27:06 +0000 Subject: [PATCH 1/3] Initial plan From a45e5584f56b68473fc2c6f2e99bb8aed2e7d8aa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:33:51 +0000 Subject: [PATCH 2/3] Fix sprintf(): Too few arguments when color tokens in format string and colorization disabled Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- lib/cli/Streams.php | 2 ++ tests/Test_Cli.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/cli/Streams.php b/lib/cli/Streams.php index 3d91d0a..89d0ca7 100755 --- a/lib/cli/Streams.php +++ b/lib/cli/Streams.php @@ -44,6 +44,8 @@ public static function render( $msg ) { // Colorize the message first so sprintf doesn't bitch at us if ( Colors::shouldColorize() ) { $args[0] = Colors::colorize( $args[0] ); + } else { + $args[0] = Colors::decolorize( $args[0] ); } // Escape percent characters for sprintf diff --git a/tests/Test_Cli.php b/tests/Test_Cli.php index d5101a2..bd4476d 100644 --- a/tests/Test_Cli.php +++ b/tests/Test_Cli.php @@ -553,4 +553,20 @@ function test_safe_strlen() { mb_detect_order( $mb_detect_order ); } } + + function test_render_with_color_tokens_and_sprintf_args_colors_disabled() { + Colors::disable( true ); + + // Color tokens in format string must not cause "sprintf(): Too few arguments". + $result = \cli\render( '[%C%k%s%N] Starting!', '2024-01-01 12:00:00' ); + $this->assertSame( '[2024-01-01 12:00:00] Starting!', $result ); + } + + function test_render_with_color_tokens_and_sprintf_args_colors_enabled() { + Colors::enable( true ); + + $result = \cli\render( '[%C%k%s%N] Starting!', '2024-01-01 12:00:00' ); + $this->assertStringContainsString( '2024-01-01 12:00:00', $result ); + $this->assertStringContainsString( 'Starting!', $result ); + } } From 26a878eef1e65fa0aa1b80870b6ad8da2b2d3b0d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:49:54 +0000 Subject: [PATCH 3/3] Update inline comment to reflect color token normalization before sprintf Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- lib/cli/Streams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/Streams.php b/lib/cli/Streams.php index 89d0ca7..71b454f 100755 --- a/lib/cli/Streams.php +++ b/lib/cli/Streams.php @@ -41,7 +41,7 @@ public static function render( $msg ) { // If the first argument is not an array just pass to sprintf if( !is_array( $args[1] ) ) { - // Colorize the message first so sprintf doesn't bitch at us + // Normalize color tokens before sprintf: colorize or strip them so no raw %tokens reach sprintf if ( Colors::shouldColorize() ) { $args[0] = Colors::colorize( $args[0] ); } else {