laravel/prompts

Can't type "0" on a text input: Uninitialized string offset 0

igorblumberg opened this issue · 0 comments

Laravel Prompts Version

0.1.0

Laravel Version

10.16.1

PHP Version

8.2.6

Operating System & Version

Ubuntu (Laravel Homestead)

Terminal Application

Oh My Zsh

Description

When I prompt the user to enter a text, if the character "0" (zero) is present in the input the command fails immediately.

$userID = text(
label: "Type the user ID"
);
$this->info($userID);

Steps To Reproduce

Run the command and type "0" in the input field.

ErrorException

Uninitialized string offset 0

at vendor/laravel/prompts/src/Concerns/TypedValue.php:43
39▕ $this->cursorPosition = strlen($this->typedValue);
40▕ }
41▕
42▕ $this->on('key', function ($key) use ($submit) {
➜ 43▕ if ($key[0] === "\e") {
44▕ match ($key) {
45▕ Key::LEFT => $this->cursorPosition = max(0, $this->cursorPosition - 1),
46▕ Key::RIGHT => $this->cursorPosition = min(strlen($this->typedValue), $this->cursorPosition + 1),
47▕ Key::DELETE => $this->typedValue = substr($this->typedValue, 0, $this->cursorPosition).substr($this->typedValue, $this->cursorPosition + 1),

  +5 vendor frames 

6 app/Console/Commands/Commit.php:30
Laravel\Prompts\text()

  +12 vendor frames 

19 artisan:35
Illuminate\Foundation\Console\Kernel::handle()