fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2406
Closed
andrewwhitecdw wants to merge 1 commit into
Closed
fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2406andrewwhitecdw wants to merge 1 commit into
andrewwhitecdw wants to merge 1 commit into
Conversation
parse_duration_to_ms 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€') because the index is not a char boundary. Split off the last character using its UTF-8 length instead, so invalid units surface the intended 'unknown duration unit' error. Add regression tests covering valid units and multi-byte input. Signed-off-by: Andrew White <andrewh@cdw.com>
andrewwhitecdw
requested review from
a team,
derekwaynecarr,
maxamillion and
mrunalp
as code owners
July 22, 2026 03:32
|
Thank you for your submission! We ask that you sign our Developer Certificate of Origin before we can accept your contribution. You can sign the DCO by adding a comment below using this text: I have read the DCO document and I hereby sign the DCO. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the DCO Assistant Lite bot. |
|
Thank you for your interest in contributing to OpenShell, @andrewwhitecdw. This project uses a vouch system for first-time contributors. Before submitting a pull request, you need to be vouched by a maintainer. To get vouched:
See CONTRIBUTING.md for details. |
This was referenced Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.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_mssplits off the last character using its UTF-8 length (char::len_utf8) instead of assuming a single byte30s,5m,1h) and a regression test for multi-byte unit 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