laravel/prompts

Discrepancy between `multiselect` return value and displayed value

irobin591 opened this issue · 1 comments

Laravel Prompts Version

0.1.5

Laravel Version

10.19.0

PHP Version

8.2.8 (in docker image)

Operating System & Version

macOS 13.5 (Intel) + Docker 4.18.0 + Dockerimage mcr.microsoft.com/devcontainers/php:1-8.2-bullseye

Terminal Application

VSCode Terminal

Description

When using multiselect prompts with arrays matching the array_is_list requirement, the selected options are displayed differently as they are returned.

Steps To Reproduce

  1. Create a new command with the following code:
$selectedPermissions = multiselect(
    'Select permissions',
    [
        'create',
        'read',
        'write',
        'delete',
    ],
    [
        'read',
        'write',
    ]
);

dump($selectedPermissions);
  1. Select the default values (read + write)
  2. Observe the discrepancy between the displayed selected permissions and the actual selected permissions:
 ┌ Select permissions ──────────────────────────────────────────┐
 │ create                                                       │
 │ read                                                         │
 └──────────────────────────────────────────────────────────────┘

array:2 [ // app/Console/Commands/Bug.php:45
  0 => "read"
  1 => "write"
]

You can find a minimal example on a brand-new Laravel project here: https://github.com/irobin591/laravel-prompts-bug (see app/Console/Commands/Bug.php)

Thanks @irobin591! I've created #53 to address this.