Skip to content

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

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

fix(cli): avoid panic on multi-byte UTF-8 in --since duration#2446
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.

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 in commands/common.rs) splits off the last character using its UTF-8 length (char::len_utf8) instead of assuming a single byte
  • Added regression tests in commands/common.rs for valid units and multi-byte 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 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>
@copy-pr-bot

copy-pr-bot Bot commented Jul 23, 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

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

All contributors have signed the DCO ✍️ ✅
Posted by the DCO Assistant Lite bot.

@andrewwhitecdw

Copy link
Copy Markdown
Author

I have read the DCO document and I hereby sign the DCO.

@johntmyers johntmyers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@johntmyers johntmyers added the gator:watch-pipeline Gator is monitoring PR CI/CD status label Jul 24, 2026
@johntmyers

Copy link
Copy Markdown
Collaborator

/ok to test 5b03877

@johntmyers johntmyers added gator:approval-needed Gator completed review; maintainer approval needed and removed gator:watch-pipeline Gator is monitoring PR CI/CD status labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gator:approval-needed Gator completed review; maintainer approval needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants