Skip to content

Commit

Permalink
Fix header name range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Jul 17, 2023
1 parent cb0e15a commit 1cf1e6d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions async-nats/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl FromStr for HeaderName {
type Err = ParseHeaderNameError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.contains(|c: char| !c.is_ascii_alphanumeric() && c != '-') {
if s.contains(|c: char| c == ':' || (c as u8) < 33 || (c as u8) > 126) {
return Err(ParseHeaderNameError);
}

Expand Down Expand Up @@ -637,6 +637,18 @@ mod tests {
);
}

#[test]
fn dollar_header_name() {
let valid_header_name = "$X_Custom_Header";
let parsed_header = HeaderName::from_str(valid_header_name);

assert!(
parsed_header.is_ok(),
"Expected Ok(HeaderName), but got an error: {:?}",
parsed_header.err()
);
}

#[test]
fn invalid_header_name_with_space() {
let invalid_header_name = "X Custom Header";
Expand All @@ -651,7 +663,7 @@ mod tests {

#[test]
fn invalid_header_name_with_special_chars() {
let invalid_header_name = "X-Header!@#";
let invalid_header_name = "X-Header:";
let parsed_header = HeaderName::from_str(invalid_header_name);

assert!(
Expand Down

0 comments on commit 1cf1e6d

Please sign in to comment.