Skip to content

Commit

Permalink
Disallow new lines in HeaderValue::from_str
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed May 25, 2023
1 parent a37dc9b commit 45b788b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions async-nats/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ impl FromStr for HeaderValue {
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.contains(['\r', '\n']) {
return Err(ParseError);
}

let mut set = HeaderValue::new();
set.value.push(s.to_string());
Ok(set)
Expand Down Expand Up @@ -420,4 +424,11 @@ mod tests {
headers.insert("Second", "SecondValue");
assert!(!headers.is_empty());
}

#[test]
fn parse_value() {
assert!("Foo\r".parse::<HeaderValue>().is_err());
assert!("Foo\n".parse::<HeaderValue>().is_err());
assert!("Foo\r\n".parse::<HeaderValue>().is_err());
}
}

0 comments on commit 45b788b

Please sign in to comment.