From e45c0503b850a3c2e8948dcae6ff7af80e29d231 Mon Sep 17 00:00:00 2001 From: Igor Blumberg Date: Fri, 28 Jul 2023 21:36:09 -0300 Subject: [PATCH 1/3] fix: Check for non-null return value from fread to handle character zero correctly --- src/Terminal.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Terminal.php b/src/Terminal.php index b74c302f..c3b4f2fc 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -24,7 +24,8 @@ class Terminal */ public function read(): string { - return fread(STDIN, 1024) ?: ''; + $terminalInput = fread(STDIN, 1024); + return is_null($terminalInput) ? '' : $terminalInput; } /** From 350b857acda2502a38d6fc598d6c3c17c344ea4e Mon Sep 17 00:00:00 2001 From: Igor Blumberg Date: Fri, 28 Jul 2023 21:49:20 -0300 Subject: [PATCH 2/3] fix: Correct check for variable type to avoid invalid is_null() call --- src/Terminal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Terminal.php b/src/Terminal.php index c3b4f2fc..18192090 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -25,7 +25,7 @@ class Terminal public function read(): string { $terminalInput = fread(STDIN, 1024); - return is_null($terminalInput) ? '' : $terminalInput; + return $terminalInput !== false ? $terminalInput : ''; } /** From 4243997ee060a8a32fd75306cbe561977efebff9 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Sat, 29 Jul 2023 13:12:31 +1000 Subject: [PATCH 3/3] Formatting --- src/Terminal.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Terminal.php b/src/Terminal.php index 18192090..7bde554e 100644 --- a/src/Terminal.php +++ b/src/Terminal.php @@ -24,8 +24,9 @@ class Terminal */ public function read(): string { - $terminalInput = fread(STDIN, 1024); - return $terminalInput !== false ? $terminalInput : ''; + $input = fread(STDIN, 1024); + + return $input !== false ? $input : ''; } /**