Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cohttp/cookie.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ module Cookie_hdr = struct
$else) *)
let cookies = List.filter (fun s -> s.[0] != '$') comps in
let split_pair nvp =
(* TODO: This is buggy for cookies with '=' in values *)
match Re_str.split_delim equals_re nvp with
match Re_str.bounded_split equals_re nvp 2 with
| [] -> ("","")
| n :: [] -> (n, "")
| n :: v :: _ -> (n, v)
Expand Down
15 changes: 13 additions & 2 deletions lib_test/test_header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ let valid_set_cookie () =
assert_equal ~printer:(fun x -> x) ~msg:"header key" "Set-Cookie" k;
assert_equal ~printer:(fun x -> x) ~msg:"header value" "key=value; domain=ocaml.org; path=/foo/bar; secure" v

let cookie_printer x =
String.concat "; " (List.map (fun (x, y) -> x ^ ":" ^ y) x)

let cookie_with_eq_val () =
let cookies = [("test","me=")] in
let (k, v) = Cohttp.Cookie.Cookie_hdr.serialize cookies in
let h = Cohttp.Header.of_list [ k, v ] in
let cookies = Cohttp.Cookie.Cookie_hdr.extract h in
assert_equal ~printer:cookie_printer cookies [("test", "me=")]

let valid_cookie () =
let cookies = [ "foo", "bar"; "a", "b" ] in
let k, v = Cohttp.Cookie.Cookie_hdr.serialize cookies in
assert_equal ~msg:"key" "cookie" k;
assert_equal ~msg:"value" "foo=bar; a=b" v;
let h = Cohttp.Header.of_list [ k, v ] in
let cookies = Cohttp.Cookie.Cookie_hdr.extract h in
let printer x = String.concat "; " (List.map (fun (x, y) -> x ^ ":" ^ y) x) in
assert_equal ~printer ~msg:"headers" [ "foo", "bar"; "a", "b" ] cookies
assert_equal ~printer:cookie_printer
~msg:"headers" [ "foo", "bar"; "a", "b" ] cookies

(* returns true if the result list contains successes only.
Copied from oUnit source as it isnt exposed by the mli *)
Expand All @@ -63,6 +73,7 @@ let _ =
"Valid Auth" >:: valid_auth;
"Valid Set-Cookie" >:: valid_set_cookie;
"Valid Cookie" >:: valid_cookie;
"Cookie with =" >:: cookie_with_eq_val;
] in
let verbose = ref false in
let set_verbose _ = verbose := true in
Expand Down