Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fuzzer with the new version of prettym #49

Merged
merged 2 commits into from
May 7, 2021
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
10 changes: 6 additions & 4 deletions lib/content_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,15 @@ module Encoder = struct
| `Iana_token v -> string ppf v
| `X_token v -> using (fun v -> "X-" ^ v) string ppf v

let cut : type a. unit -> (a, a) order = fun () -> break ~indent:1 ~len:0

let value =
using
(function `Token x -> `Atom x | `String x -> `String x)
Mailbox.Encoder.word

let parameter ppf (key, v) =
eval ppf [ box; !!string; cut; char $ '='; cut; !!value; close ] key v
eval ppf [ box; !!string; cut (); char $ '='; cut (); !!value; close ] key v

let parameters ppf parameters =
let sep ppf () = eval ppf [ char $ ';'; fws ] in
Expand All @@ -628,13 +630,13 @@ module Encoder = struct
match t.parameters with
| [] ->
eval ppf
[ bbox; !!ty; cut; char $ '/'; cut; !!subty; close ]
[ bbox; !!ty; cut (); char $ '/'; cut (); !!subty; close ]
t.ty t.subty
| _ ->
eval ppf
[
bbox; !!ty; cut; char $ '/'; cut; !!subty; cut; char $ ';'; fws;
!!parameters; close;
bbox; !!ty; cut (); char $ '/'; cut (); !!subty; cut (); char $ ';';
fws; !!parameters; close;
]
t.ty t.subty t.parameters
end
37 changes: 23 additions & 14 deletions lib/mailbox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@ module Encoder = struct
| `Atom x -> eval ppf atom x
| `String x -> eval ppf str (escape_string x)

let dot = ((fun ppf () -> eval ppf [ cut; char $ '.'; cut ]), ())
let comma = ((fun ppf () -> eval ppf [ cut; char $ ','; cut ]), ())
let cut : type a. unit -> (a, a) order = fun () -> break ~indent:1 ~len:0
(* XXX(dinosaure): we must ensure that a break insert (if we really apply
* it) a space at the beginning of the new line! [Prettym.cut] does not do
* that, it only gives the opportunity to break a new line without indentation.
*
* It safe to use [Prettym.cut] only inside a [tbox] in this context - to not
* really break the mailbox. Note that such point is due to the release of
* [prettym.0.0.1] which slightly change the semantic of [fws] and [cut]. *)

let dot = ((fun ppf () -> eval ppf [ cut (); char $ '.'; cut () ]), ())
let comma = ((fun ppf () -> eval ppf [ cut (); char $ ','; cut () ]), ())
let local ppf lst = eval ppf [ box; !!(list ~sep:dot word); close ] lst
let ipaddr_v4 = using Ipaddr.V4.to_string string
let ipaddr_v6 = using Ipaddr.V6.to_string string
Expand All @@ -88,24 +97,24 @@ module Encoder = struct
eval ppf [ box; !!(list ~sep:dot boxed_string); close ] domain
| `Literal literal ->
eval ppf
[ box; char $ '['; cut; !!string; cut; char $ ']'; close ]
[ box; char $ '['; cut (); !!string; cut (); char $ ']'; close ]
literal
| `Addr (Emile.IPv4 ip) ->
eval ppf
[ box; char $ '['; cut; !!ipaddr_v4; cut; char $ ']'; close ]
[ box; char $ '['; cut (); !!ipaddr_v4; cut (); char $ ']'; close ]
ip
| `Addr (Emile.IPv6 ip) ->
eval ppf
[
box; char $ '['; cut; string $ "IPv6:"; cut; !!ipaddr_v6; cut;
char $ ']'; close;
box; char $ '['; cut (); string $ "IPv6:"; cut (); !!ipaddr_v6;
cut (); char $ ']'; close;
]
ip
| `Addr (Emile.Ext (ldh, v)) ->
eval ppf
[
box; char $ '['; cut; !!string; cut; char $ ':'; cut; !!string; cut;
char $ ']'; close;
box; char $ '['; cut (); !!string; cut (); char $ ':'; cut ();
!!string; cut (); char $ ']'; close;
]
ldh v

Expand Down Expand Up @@ -136,13 +145,13 @@ module Encoder = struct
| Some name, (x, []) ->
eval ppf
[
box; !!phrase; spaces 1; char $ '<'; cut; !!local; cut; char $ '@';
cut; !!domain; cut; char $ '>'; close;
box; !!phrase; spaces 1; char $ '<'; cut (); !!local; cut ();
char $ '@'; cut (); !!domain; cut (); char $ '>'; close;
]
name t.Emile.local x
| None, (x, []) ->
eval ppf
[ box; !!local; cut; char $ '@'; cut; !!domain; close ]
[ !!local; cut (); char $ '@'; cut (); !!domain ]
t.Emile.local x
| name, (x, r) ->
let domains ppf lst =
Expand All @@ -155,9 +164,9 @@ module Encoder = struct

eval ppf
[
box; !!(option phrase); cut; char $ '<'; cut; !!domains; cut;
char $ ':'; cut; !!local; cut; char $ '@'; cut; !!domain; cut;
char $ '>'; close;
box; !!(option phrase); cut (); char $ '<'; cut (); !!domains;
cut (); char $ ':'; cut (); !!local; cut (); char $ '@'; cut ();
!!domain; cut (); char $ '>'; close;
]
name r t.Emile.local x

Expand Down
1 change: 1 addition & 0 deletions mrmime.opam
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ depends: [
"hxd" {with-test}
"alcotest" {with-test}
"jsonm" {with-test}
"crowbar" {with-test}
]