From a094475810bb24aa26a66a9c2127b9a10de470d2 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 7 May 2021 10:53:18 +0200 Subject: [PATCH 1/2] Fix fuzzer with the new version of prettym --- lib/content_type.ml | 10 ++++++---- lib/mailbox.ml | 37 +++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/content_type.ml b/lib/content_type.ml index 5d3c3d0..4d055c9 100644 --- a/lib/content_type.ml +++ b/lib/content_type.ml @@ -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 @@ -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 diff --git a/lib/mailbox.ml b/lib/mailbox.ml index d788629..847237b 100644 --- a/lib/mailbox.ml +++ b/lib/mailbox.ml @@ -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 @@ -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 @@ -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 = @@ -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 From 891548bb0db92a8f2d9ddb0ac834bdac37c22ab4 Mon Sep 17 00:00:00 2001 From: Romain Calascibetta Date: Fri, 7 May 2021 11:15:20 +0200 Subject: [PATCH 2/2] Add crowbar as a test dependency for mrmime --- mrmime.opam | 1 + 1 file changed, 1 insertion(+) diff --git a/mrmime.opam b/mrmime.opam index 2b69d7e..cc1c94d 100644 --- a/mrmime.opam +++ b/mrmime.opam @@ -36,4 +36,5 @@ depends: [ "hxd" {with-test} "alcotest" {with-test} "jsonm" {with-test} + "crowbar" {with-test} ]