Repository navigation
fix(git): fix panic on multibyte chars in commit output - #1266
Merged
aeppling merged 2 commits intoJun 3, 2026
Merged
Conversation
git commit on an initial commit under a Chinese locale outputs: [master(根提交) fb597ec] Initial commit The old code found the first space and sliced line[1..hash_start], yielding "master(根提交)" (21 bytes). hash.len() >= 7 was true, so it tried &hash[..7] — but byte 7 falls inside the 3-byte '(' character, causing a panic. Two bugs were present: 1. Logic: the code grabbed the token *before* the first space (branch name), not the commit hash. The hash is always the last whitespace-separated token inside the [...] brackets. 2. Safety: raw byte slicing on a potentially non-ASCII string. Fix: find ']', extract the bracket content, split_whitespace() and take next_back() to get the hash. Use chars().take(7) for the short-hash slice so it is always char-boundary-safe.
Collaborator
📊 Automated PR Analysis
SummaryFixes a panic caused by slicing into multibyte UTF-8 characters when parsing git commit output under non-ASCII locales (e.g., Chinese). The fix correctly extracts the commit hash as the last token within brackets and uses char-safe slicing instead of raw byte indexing. Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
…yte branch names Extracts parse_commit_output into a testable helper function and adds 7 comprehensive unit tests covering: - Normal branch names - Root-commit annotations - Multibyte branch names (Chinese, Thai) — regression test for the panic fix - Edge cases (no bracket, short hash, empty input) Tests verify the fix handles UTF-8 safely by anchoring on ']' and using char-safe slicing. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Contributor
|
Hey @shalk , thanks for the fix and sorry for the delay This look good to me |
aeppling
approved these changes
Jun 3, 2026
Merged
social4hyq
pushed a commit
to social4hyq/homebrew-core
that referenced
this pull request
Sep 20, 2026
rtk 0.42.3 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## [0.42.3](rtk-ai/rtk@v0.42.2...v0.42.3) (2026-06-05) ### Feats - feat(copilot): CLI native integration #2101 ### Fix - fix(docs): replace remaining MIT license references with Apache 2.0 [#2084](rtk-ai/rtk#2084) - fix: prevent crashes when output is piped rtk-ai/rtk#1048 close rtk-ai/rtk#1004 - fix(grep): parse single-file output containing colons rtk-ai/rtk#1554; close rtk-ai/rtk#1436. - fix(ls): preserve permission info as octal when -l/-la is passed rtk-ai/rtk#1675 - fix(cicd): MIT to Apache 2.0 [#2092](rtk-ai/rtk#2092) - fix(pkg): rtk is Apache 2.0 and no MIT [#2082](rtk-ai/rtk#2082) - fix(hook): collapse bash line continuations before matching #1572 close Hook matcher: leading backslash-newline defeats command rewrite #1564 - fix(gh,glab): don't pre-reject view/checks/run subcommands missing the id rtk-ai/rtk#2123 - fix(git): fix panic on multibyte chars in commit output rtk-ai/rtk#1266 ### Other - docs(readme): add Portuguese translation #2128 - doc(init): fix documentation inconsistencies arount rtk init rtk-ai/rtk#2173 - fix(provider): sanatize more chars when encoding claude code project pathes https://github.com/rtk-ai/rtk/pull/2172</pre> <p>View the full release notes at <a href="https://github.com/rtk-ai/rtk/releases/tag/v0.42.3">https://github.com/rtk-ai/rtk/releases/tag/v0.42.3</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!10665
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.
git commit on an initial commit under a Chinese locale outputs:
[master(根提交) fb597ec] Initial commit
The old code found the first space and sliced line[1..hash_start], yielding "master(根提交)" (21 bytes). hash.len() >= 7 was true, so it tried &hash[..7] — but byte 7 falls inside the 3-byte '(' character, causing a panic.
Two bugs were present:
Fix: find ']', extract the bracket content, split_whitespace() and take next_back() to get the hash. Use chars().take(7) for the short-hash slice so it is always char-boundary-safe.
Summary
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspected