Repository navigation
fix: keep output truncation on a UTF-8 character boundary - #176
Open
ferdingler wants to merge 1 commit into
Open
ferdingler wants to merge 1 commit into
ferdingler wants to merge 1 commit into
Conversation
9 of 10 tasks
This branch has not been deployed
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.
Description
When output hits the
max_outputlimit, the shell cuts it at a byte count. If that byte lands in the middle of a multibyte character, the shell panics instead of truncating. Something as small asX=$(printf abc; printf é)with a 4-byte limit crashes it, both in command substitution and in captured top-level output, and the CLI hits the same crash.Now the cut moves back to the start of the character it would have split, so the output stays valid UTF-8 and never goes over the limit. The limit itself, what counts toward it, and the "limit exceeded" message and exit status are unchanged. Box's copy of Shell already cuts top-level output safely (here), but command substitution has the same crash there (here), so this fixes it there too once Box moves to upstream.
I added tests for a multibyte character crossing the limit in both places, plus ASCII and exact-limit cases. Without the fix they panic; with it they pass, and the rest of the suite still passes. I also ran the original repro through the CLI with a config limit, and it now prints the truncated value instead of crashing. This touches the same file as #169 and #173 but in different spots.
Related Issues
None.
Documentation PR
None.
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.