Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ public static function generateDimensions()
static::$width = (int) $matches[2];
}
}
} elseif (($size = exec('stty size')) && preg_match('/(\d+)\s+(\d+)/', $size, $matches)) {
} elseif (($size = exec('stty size 2>/dev/null')) && preg_match('/(\d+)\s+(\d+)/', $size, $matches)) {
static::$height = (int) $matches[1];
static::$width = (int) $matches[2];
} else {
Expand Down
28 changes: 28 additions & 0 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use CodeIgniter\Test\StreamFilterTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
use ReflectionProperty;

/**
Expand Down Expand Up @@ -594,6 +595,33 @@ public function testWindow(): void
$this->assertIsInt(CLI::getWidth());
}

#[RequiresOperatingSystem('Darwin|Linux')]
public function testGenerateDimensionsDoesNotLeakSttyErrorToStderr(): void
{
$code = <<<'PHP'
require __DIR__ . '/system/Test/bootstrap.php';
CodeIgniter\CLI\CLI::generateDimensions();
PHP;

$cmd = sprintf('%s -r %s < /dev/null', PHP_BINARY, escapeshellarg($code));

$proc = proc_open(
$cmd,
[1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes,
ROOTPATH,
);
$this->assertIsResource($proc);

stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($proc);

$this->assertSame('', $stderr);
}

/**
* @param array $tbody
* @param array $thead
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.7.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Bugs Fixed
**********

- **Autoloader:** Fixed a bug where ``Autoloader::unregister()`` (used during tests) silently failed to remove handlers from the SPL autoload stack, causing closures to accumulate permanently.
- **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``stty`` error output (e.g., ``stty: 'standard input': Inappropriate ioctl for device``) to stderr when stdin was not a TTY.
- **Commands:** Fixed a bug in the ``env`` command where passing options only would cause the command to throw a ``TypeError`` instead of showing the current environment.
- **Common:** Fixed a bug where the ``command()`` helper function did not properly clean up output buffers, which could lead to risky tests when exceptions were thrown.
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.
Expand Down
Loading