Skip to content
Open
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
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ public static function generateDimensions()
static::$height = (int) $matches[1];
static::$width = (int) $matches[2];
} else {
static::$height = (int) exec('tput lines');
static::$width = (int) exec('tput cols');
static::$height = (int) exec('tput lines 2>/dev/null');
static::$width = (int) exec('tput cols 2>/dev/null');
}
} catch (Throwable $e) {
// Reset the dimensions so that the default values will be returned later.
Expand Down
25 changes: 24 additions & 1 deletion tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,28 @@ public function testWindow(): void

#[RequiresOperatingSystem('Darwin|Linux')]
public function testGenerateDimensionsDoesNotLeakSttyErrorToStderr(): void
{
$this->assertSame('', $this->captureGenerateDimensionsStderr());
}

#[RequiresOperatingSystem('Darwin|Linux')]
public function testGenerateDimensionsDoesNotLeakTputErrorToStderrWhenTermIsUnset(): void
{
$env = getenv();
unset($env['TERM']);

$this->assertSame('', $this->captureGenerateDimensionsStderr($env));
}

/**
* Spawns a child PHP process that calls `CLI::generateDimensions()` with
* `STDIN` pointed at `/dev/null` (forcing the non-TTY code path), and
* returns whatever it wrote to stderr.
*
* @param array<string, string>|null $env Environment for the child process.
* `null` inherits the parent env.
*/
private function captureGenerateDimensionsStderr(?array $env = null): string
{
$code = <<<'PHP'
require __DIR__ . '/system/Test/bootstrap.php';
Expand All @@ -610,6 +632,7 @@ public function testGenerateDimensionsDoesNotLeakSttyErrorToStderr(): void
[1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
$pipes,
ROOTPATH,
$env,
);
$this->assertIsResource($proc);

Expand All @@ -619,7 +642,7 @@ public function testGenerateDimensionsDoesNotLeakSttyErrorToStderr(): void
fclose($pipes[2]);
proc_close($proc);

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

/**
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 @@ -38,6 +38,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.
- **CLI:** Fixed a bug where ``CLI::generateDimensions()`` leaked ``tput`` error output (``tput: No value for $TERM and no -T specified``) to stderr when the ``stty`` fallback was reached and the ``TERM`` environment variable was not set.
- **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.
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
Expand Down
Loading