Skip to content

Commit

Permalink
Fix percent-encoding of percent sign in grpc-message header
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDog committed Dec 25, 2024
1 parent a8c1e39 commit 40e4a1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tonic/src/metadata/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ mod tests {
#[test]
fn test_to_headers_encoding() {
use crate::Status;
let special_char_message = "Beyond ascii \t\n\r🌶️💉💧🐮🍺";
let special_char_message = "Beyond 100% ascii \t\n\r🌶️💉💧🐮🍺";
let s1 = Status::unknown(special_char_message);

assert_eq!(s1.message(), special_char_message);
Expand All @@ -2509,6 +2509,17 @@ mod tests {
let s2 = Status::from_header_map(&s1_map).unwrap();

assert_eq!(s1.message(), s2.message());

assert!(
s1_map
.get("grpc-message")
.unwrap()
.to_str()
.unwrap()
.starts_with("Beyond%20100%25%20ascii"),
"Percent sign or other character isn't encoded as desired: {:?}",
s1_map.get("grpc-message")
);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ENCODING_SET: &AsciiSet = &CONTROLS
.add(b' ')
.add(b'"')
.add(b'#')
.add(b'%')
.add(b'<')
.add(b'>')
.add(b'`')
Expand Down

0 comments on commit 40e4a1a

Please sign in to comment.