fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2446
fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2446andrewwhitecdw wants to merge 1 commit into
Conversation
parse_duration_to_ms was moved to commands/common.rs since the original PR was opened, but it still split the last byte of the input with split_at(s.len() - 1), which panics when the final character is multi-byte UTF-8 (e.g. 'openshell logs my-sandbox --since 5€'). Split off the last character using its UTF-8 length instead, so invalid units surface the intended 'unknown duration unit' error. Add regression tests in commands/common.rs. Signed-off-by: Andrew White <andrewh@cdw.com>
|
All contributors have signed the DCO ✍️ ✅ |
|
I have read the DCO document and I hereby sign the DCO. |
johntmyers
left a comment
There was a problem hiding this comment.
gator-agent
PR Review Status
Validation: This is a project-valid, concentrated CLI bug fix that prevents openshell logs --since from panicking on a multi-byte UTF-8 unit. It supersedes #2406, which was closed only by the earlier vouch gate.
Head SHA: 5b038779924ad59313f71d6cfafe1f7d40ee1c1f
Review findings:
- No blocking or actionable findings remain. The UTF-8 boundary calculation is correct and the regression tests cover both
5€and a multi-byte-only input.
Docs: Not needed because this preserves the documented CLI contract and replaces a crash with the intended validation error.
E2E: Not required for this isolated duration-parser fix; no sandbox lifecycle, gateway, policy, network, credential, driver, GPU, Kubernetes, or packaging behavior changes.
Next state: gator:watch-pipeline
|
/ok to test 5b03877 |
Summary
openshell logs <name> --since <duration>panics when the duration's last character is multi-byte UTF-8 (e.g.--since 5€).parse_duration_to_mssplit the input withsplit_at(s.len() - 1), indexing by byte length, which is not a char boundary for multi-byte characters. The CLI now returns the intended "unknown duration unit" error instead of crashing.This PR supersedes #2406, which was auto-closed by the vouch-check workflow before I was vouched.
Related Issue
N/A — small fix found during code review (panic verified with a standalone repro:
"5€".split_at(3)→byte index 3 is not a char boundary).Changes
parse_duration_to_ms(now incommands/common.rs) splits off the last character using its UTF-8 length (char::len_utf8) instead of assuming a single bytecommands/common.rsfor valid units and multi-byte inputTesting
mise run pre-commitpasses (mise unavailable in this environment; ran equivalentcargo fmt+cargo clippy -p openshell-cli --all-targets— clean)cargo test -p openshell-cli parse_duration_to_ms— 2 passed)Checklist