Preserve UTF-8 when sanitizing RESP strings - #243
Open
stevenzengg wants to merge 2 commits into
Open
Conversation
Signed-off-by: Steven Zeng <szeng2@atlassian.com>
stevenzengg
force-pushed
the
fix/preserve-utf8-resp-strings
branch
from
August 25, 2026 06:37
55c33b6 to
426151c
Compare
Signed-off-by: Steven Zeng <szeng2@atlassian.com>
Author
|
@dmitrypol, could you review this small UTF-8 correctness fix when you have a chance? It prevents invalid RESP output (and a possible interior-NUL panic) in the shared string-sanitization helper, with focused Unicode and forbidden-character coverage. I don't have permission to assign reviewers or labels on this repository. Could a maintainer also add the |
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.
Summary
Context::str_as_legal_resp_stringpreviously converted every Rustcharwithchar as u8, truncating Unicode scalar values instead of preserving their UTF-8 encoding.For example:
éshould be encoded asC3 A9, but the previous code produced onlyE9, so strict UTF-8 clients reject the response.😀was truncated to00, which could makeCString::new(...).unwrap()panic because it creates an interior NUL.This change replaces only CR, LF, and NUL with ASCII spaces while preserving every other character's UTF-8 encoding.
The shared helper affects:
Test plan
Passed locally:
cargo test legal_resp_string_— 4 passedcargo fmt -- --checkcargo build --all --all-targets --no-default-featurescargo build --all --all-targets --no-default-features --releasecargo test --doc --workspace --no-default-features --release— 3 passed, 3 ignoredcargo deny check licensescargo deny check bansWorkspace suite:
test_valkey_value_derivecrashes the locally installed Valkey 9.1.0 ingetKeysUsingLegacyRangeSpec; the identical failure reproduces on untouchedmain, so it is not introduced by this change.