diff --git a/cohttp/cookie.ml b/cohttp/cookie.ml index 4595734254..21e9864797 100644 --- a/cohttp/cookie.ml +++ b/cohttp/cookie.ml @@ -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) diff --git a/lib_test/test_header.ml b/lib_test/test_header.ml index edf5061c7e..9d9f95e9eb 100644 --- a/lib_test/test_header.ml +++ b/lib_test/test_header.ml @@ -35,6 +35,16 @@ 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 @@ -42,8 +52,8 @@ let valid_cookie () = 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 *) @@ -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