Skip to content

Commit 66c900f

Browse files
committed
Fix supporting space in cookie storage cookie values.
1 parent 7b1e93c commit 66c900f

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

integration/hurl/tests_ok/cookie/cookie_jar.hurl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Set-Cookie: LSID=DQAAAKEaem_vYg; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly
88
Set-Cookie: HSID=AYQEVnDKrdst; Domain=localhost; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly; Path=/
99
Set-Cookie: SSID=Ap4PGTEq; Domain=localhost; Expires=Thu, 13 Jan 2078 22:23:01 GMT; HttpOnly; Path=/
1010
[Asserts]
11-
header "Set-Cookie" count == 3
11+
header "Set-Cookie" count == 4
1212
cookie "LSID" == "DQAAAKEaem_vYg"
1313
cookie "LSID[Value]" == "DQAAAKEaem_vYg"
1414
cookie "LSID[Expires]" exists
@@ -19,3 +19,6 @@ cookie "LSID[Path]" == "/accounts"
1919
cookie "LSID[Secure]" not exists
2020
cookie "LSID[HttpOnly]" exists
2121
cookie "LSID[SameSite]" not exists
22+
# Following RFC-6265, we should not have spaces in cookie value, but curl accepts it, considering
23+
# the double quotes to be part of the value.
24+
cookie "foo" == "\"a b\""

integration/hurl/tests_ok/cookie/cookie_jar.out.pattern

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
#HttpOnly_localhost FALSE /accounts FALSE <<<(17\d{8}|3409338181)>>> LSID DQAAAKEaem_vYg
66
#HttpOnly_.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> HSID AYQEVnDKrdst
77
#HttpOnly_.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> SSID Ap4PGTEq
8+
.localhost TRUE / FALSE <<<(17\d{8}|3409338181)>>> foo "a b"

integration/hurl/tests_ok/cookie/cookie_jar.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ def set_cookie_jar():
2828
expires="Thu, 13 Jan 2078 22:23:01 GMT",
2929
httponly=True,
3030
)
31+
resp.set_cookie(
32+
"foo",
33+
"a b",
34+
domain="localhost",
35+
path="/",
36+
expires="Thu, 13 Jan 2078 22:23:01 GMT",
37+
httponly=False,
38+
)
3139
return resp

integration/hurl/tests_ok/cookie/cookie_storage.hurl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# manage cookie store
44
#
55

6-
# @cookie_storage_set: localhost FALSE / FALSE 0 cookie1 valueA
6+
# @cookie_storage_set: localhost FALSE / FALSE 0 cookie1 valueA
77
GET http://localhost:8000/cookie-storage/assert-that-cookie1-is-valueA
88
HTTP 200
99

packages/hurl/src/http/cookie.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
use core::fmt;
1919
use std::fmt::Formatter;
2020

21-
use crate::util::redacted::Redact;
22-
2321
/// [Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) returned by
2422
/// the server with `Set-Cookie` header, and saved in the cookie storage of the internal HTTP
2523
/// engine.
@@ -78,9 +76,9 @@ impl Cookie {
7876
)
7977
}
8078

81-
/// Creates a [`Cookie`] from a Nescape cookie formatted string.
79+
/// Creates a [`Cookie`] from a Netscape cookie formatted string.
8280
pub fn from_netscape_str(s: &str) -> Result<Self, ParseCookieError> {
83-
let tokens = s.split_ascii_whitespace().collect::<Vec<&str>>();
81+
let tokens = s.split("\t").collect::<Vec<&str>>();
8482
let (http_only, domain) = if let Some(&v) = tokens.first() {
8583
if let Some(domain) = v.strip_prefix("#HttpOnly_") {
8684
(true, domain.to_string())
@@ -140,22 +138,6 @@ impl fmt::Display for Cookie {
140138
}
141139
}
142140

143-
impl Redact for Cookie {
144-
fn redact(&self, secrets: &[impl AsRef<str>]) -> String {
145-
format!(
146-
"{}{}\t{}\t{}\t{}\t{}\t{}\t{}",
147-
if self.http_only { "#HttpOnly_" } else { "" },
148-
self.domain,
149-
self.include_subdomain,
150-
self.path,
151-
self.https,
152-
self.expires,
153-
self.name,
154-
self.value.redact(secrets)
155-
)
156-
}
157-
}
158-
159141
#[derive(Clone, Debug, PartialEq, Eq)]
160142
pub struct ParseCookieError;
161143

packages/hurl/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn create_cookies_file(
329329
s.push_str(&format!("# Cookies for file <{}>", run.filename));
330330
s.push('\n');
331331
for cookie in run.hurl_result.cookies.iter() {
332-
s.push_str(&cookie.redact(secrets));
332+
s.push_str(&cookie.to_netscape_str().redact(secrets));
333333
s.push('\n');
334334
}
335335
}

0 commit comments

Comments
 (0)