Skip to content

Commit a8a41bc

Browse files
authored
Misc: improve doc for Url.decode_arguments (#1019)
1 parent 013ecf1 commit a8a41bc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/js_of_ocaml/url.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ val encode_arguments : (string * string) list -> string
7777

7878
val decode_arguments : string -> (string * string) list
7979
(** [decode_arguments s] parses [s] returning the sliced-diced
80-
association list. *)
80+
association list. [s] should be only the arguments part (after the '?')
81+
not the whole url. *)
8182

8283
(** The following part allow one to handle Url object in a much higher level
8384
than what a string provides. *)

lib/tests/test_url.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,20 @@ let%expect_test _ =
3939
then ()
4040
else print_endline "escaping error";
4141
[%expect {||}]
42+
43+
let%expect_test "[decode_arguments]" =
44+
let test url =
45+
ListLabels.iter (Url.decode_arguments url) ~f:(fun (key, value) ->
46+
Printf.printf "'%s' => '%s'\n" key value)
47+
in
48+
(* Incorrect usage: passing in full url. *)
49+
test "https://foo.com/?foo=bar&baz%20=qux%22quux";
50+
[%expect {|
51+
'https://foo.com/?foo' => 'bar'
52+
'baz ' => 'qux"quux' |}];
53+
(* correct usage: only the arguments part *)
54+
test "foo=bar&baz%20=qux%22quux";
55+
[%expect {|
56+
'foo' => 'bar'
57+
'baz ' => 'qux"quux' |}];
58+
ignore ()

0 commit comments

Comments
 (0)