File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ let percent_encode ?(skip = fun _ -> false) s =
55 | c when skip c -> Buffer. add_char buf c
66 | ( ' ' | '!' | '"' | '#' | '$' | '%' | '&' | '\' ' | '(' | ')' | '*' | '+'
77 | ',' | '/' | ':' | ';' | '=' | '?' | '@' | '[' | ']' | '~' ) as c ->
8- Printf. bprintf buf " %%%X " (Char. code c)
8+ Printf. bprintf buf " %%%02X " (Char. code c)
99 | c when Char. code c < 32 || Char. code c > 127 ->
10- Printf. bprintf buf " %%%X " (Char. code c)
10+ Printf. bprintf buf " %%%02X " (Char. code c)
1111 | c -> Buffer. add_char buf c)
1212 s;
1313 Buffer. contents buf
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ module U = Util
44
55let () = assert_eq " hello%20world" (U. percent_encode " hello world" )
66let () = assert_eq " %23%25^%24%40^%40" (U. percent_encode " #%^$@^@" )
7+ let () = assert_eq " %0F" (U. percent_encode " \015 " )
78
89let () =
910 assert_eq " a%20ohm%2B5235%25%26%40%23%20---%20_"
@@ -13,11 +14,15 @@ let () = assert_eq (Some "?") (U.percent_decode @@ U.percent_encode "?")
1314
1415let () =
1516 add_qcheck
16- @@ QCheck.Test. make ~count: 1_000 ~long_factor: 20 Q. string (fun s ->
17+ @@ QCheck.Test. make ~name: __LOC__ ~count: 1_000 ~long_factor: 20 Q. string
18+ (fun s ->
1719 String. iter (fun c -> Q. assume @@ is_ascii_char c) s;
1820 match U. percent_decode (U. percent_encode s) with
1921 | Some s' -> s = s'
20- | None -> Q.Test. fail_report " invalid percent encoding" )
22+ | None ->
23+ Q.Test. fail_reportf
24+ " invalid percent encoding of %S (encoding is %S, fails to decode)"
25+ s (U. percent_encode s))
2126
2227let () = assert_eq [ " a" ; " b" ] (U. split_on_slash " /a/b" )
2328let () = assert_eq [ " coucou" ; " lol" ] (U. split_on_slash " /coucou/lol" )
@@ -34,7 +39,7 @@ let () = assert_eq (Ok [ "foo", "bar" ]) (U.parse_query "yolo#foo=bar")
3439
3540let () =
3641 add_qcheck
37- @@ QCheck.Test. make ~long_factor: 20 ~count: 1_000
42+ @@ QCheck.Test. make ~name: __LOC__ ~ long_factor:20 ~count: 1_000
3843 Q. (small_list (pair string string ))
3944 (fun l ->
4045 List. iter
You can’t perform that action at this time.
0 commit comments