diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-20 18:08:58 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-20 18:08:58 +0900 |
| commit | dbb91e0c4b61b7c1106a9d3aefcab6f2598b93d4 (patch) | |
| tree | b07faf2873e1e62a7ba87139c71595a96b25a675 /crates/shirabe/src/command | |
| parent | daa580b97ad2d585c100927842ba88e891eb9aca (diff) | |
| download | php-shirabe-dbb91e0c4b61b7c1106a9d3aefcab6f2598b93d4.tar.gz php-shirabe-dbb91e0c4b61b7c1106a9d3aefcab6f2598b93d4.tar.zst php-shirabe-dbb91e0c4b61b7c1106a9d3aefcab6f2598b93d4.zip | |
fix(search-command): avoid usize overflow panic when truncating description
The negated remaining-width subtraction was cast straight to usize,
overflowing whenever it went negative (e.g. an abandoned-package
warning ate the available width) and panicking on slice indexing.
Route through the shim's substr(), which mirrors PHP's negative-length
semantics and clamps instead of overflowing.
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/search_command.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs index 1f77889e..156dd406 100644 --- a/crates/shirabe/src/command/search_command.rs +++ b/crates/shirabe/src/command/search_command.rs @@ -17,7 +17,7 @@ use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, preg_quote}; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, preg_quote, substr}; #[derive(Debug)] pub struct SearchCommand { @@ -230,7 +230,7 @@ impl Command for SearchCommand { }; let remaining = width - name_length - warning.len() as i64 - 2; let description = if description.len() as i64 > remaining { - format!("{}...", &description[..(remaining - 3) as usize]) + format!("{}...", substr(&description, 0, Some(remaining - 3))) } else { description }; |
