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 =
5
5
| c when skip c -> Buffer. add_char buf c
6
6
| ( ' ' | '!' | '"' | '#' | '$' | '%' | '&' | '\' ' | '(' | ')' | '*' | '+'
7
7
| ',' | '/' | ':' | ';' | '=' | '?' | '@' | '[' | ']' | '~' ) as c ->
8
- Printf. bprintf buf " %%%X " (Char. code c)
8
+ Printf. bprintf buf " %%%02X " (Char. code c)
9
9
| 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)
11
11
| c -> Buffer. add_char buf c)
12
12
s;
13
13
Buffer. contents buf
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ module U = Util
4
4
5
5
let () = assert_eq " hello%20world" (U. percent_encode " hello world" )
6
6
let () = assert_eq " %23%25^%24%40^%40" (U. percent_encode " #%^$@^@" )
7
+ let () = assert_eq " %0F" (U. percent_encode " \015 " )
7
8
8
9
let () =
9
10
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 "?")
13
14
14
15
let () =
15
16
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 ->
17
19
String. iter (fun c -> Q. assume @@ is_ascii_char c) s;
18
20
match U. percent_decode (U. percent_encode s) with
19
21
| 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))
21
26
22
27
let () = assert_eq [ " a" ; " b" ] (U. split_on_slash " /a/b" )
23
28
let () = 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")
34
39
35
40
let () =
36
41
add_qcheck
37
- @@ QCheck.Test. make ~long_factor: 20 ~count: 1_000
42
+ @@ QCheck.Test. make ~name: __LOC__ ~ long_factor:20 ~count: 1_000
38
43
Q. (small_list (pair string string ))
39
44
(fun l ->
40
45
List. iter
You can’t perform that action at this time.
0 commit comments