fix(core): preserve unicode in grep previews - #42356
Merged
Merged
Conversation
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.
What
Prevent oversized Ripgrep line previews from persisting half of a Unicode character. A malformed preview could display as
�and poison subsequent provider requests.Before / After
Before
A grep match longer than 2,000 JavaScript string units could place an emoji across the preview boundary.
slice(0, 2_000)retained only the emoji's first UTF-16 code unit, which JSON serialized as an unpaired\ud83d. The TUI displayed a replacement character, and OpenAI rejected later requests with HTTP 400 because the request body was not valid Unicode JSON.After
When the preview cutoff lands after the first half of a Unicode character, Ripgrep drops that incomplete code unit before appending the truncation marker. Persisted tool output remains valid Unicode and can be submitted to providers.
How
packages/core/src/ripgrep.ts: remove a trailing unmatched high-surrogate code unit from truncated line previews.packages/core/test/ripgrep.test.ts: cover an emoji crossing the exact 2,000-unit preview boundary.Scope
This fixes the producer that created the malformed durable tool output. It does not add a provider-request sanitizer or rewrite existing session history.
Testing
bun run test test/ripgrep.test.tsfrompackages/core: 3 passedbun typecheckfrompackages/core: passed\ud83d: HTTP 400Invalid body: failed to parse JSON value