Skip to content

Commit

Permalink
Fix parsing of quoted cookie values
Browse files Browse the repository at this point in the history
Previously one extra character was getting stripped from the end.
This commit fixes the index while stripping the end quote.
  • Loading branch information
theawless committed Jan 3, 2021
1 parent 18ee975 commit 6fb0c95
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/cookies/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl PartialEq<String> for Cookie {
fn parse_cookie_value(mut bytes: &[u8]) -> Result<&str, ParseError> {
// Strip quotes, but only if in a legal pair.
if bytes.starts_with(b"\"") && bytes.ends_with(b"\"") {
bytes = &bytes[1..bytes.len() - 2];
bytes = &bytes[1..bytes.len() - 1];
}

// Validate the bytes are all legal cookie octets.
Expand Down Expand Up @@ -301,9 +301,10 @@ mod tests {
assert!(Cookie::parse(s).is_err());
}

#[test]
fn parse_simple() {
let cookie = Cookie::parse("foo=bar").unwrap();
#[test_case("foo=bar")]
#[test_case(r#"foo="bar""#)]
fn parse_simple(s: &str) {
let cookie = Cookie::parse(s).unwrap();

assert_eq!(cookie.name(), "foo");
assert_eq!(cookie.value(), "bar");
Expand Down

0 comments on commit 6fb0c95

Please sign in to comment.