Skip to content

fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2406

Closed
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:fix-cli-since-duration-utf8-panic/aw
Closed

fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2406
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:fix-cli-since-duration-utf8-panic/aw

Conversation

@andrewwhitecdw

Copy link
Copy Markdown

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_ms split the input with split_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_ms splits off the last character using its UTF-8 length (char::len_utf8) instead of assuming a single byte
  • Added unit tests for valid units (30s, 5m, 1h) and a regression test for multi-byte unit input

Testing

  • mise run pre-commit passes (mise unavailable in this environment; ran equivalent cargo fmt + cargo clippy -p openshell-cli --all-targets — clean)
  • Unit tests added/updated (cargo test -p openshell-cli parse_duration_to_ms — 2 passed)
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)
  • Architecture docs updated (if applicable)

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>
@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown

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:

  1. Open a Vouch Request discussion.
  2. Describe what you want to change and why.
  3. Write in your own words — do not have an AI generate the request.
  4. A maintainer will comment /vouch if approved.
  5. Once vouched, open a new PR (preferred) or reopen this one after a few minutes.

See CONTRIBUTING.md for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant