From d74e7186a24104b21a19006448c1a85d7136c6d4 Mon Sep 17 00:00:00 2001 From: Anurag Soni Date: Sun, 19 Jan 2020 18:08:16 -0500 Subject: [PATCH] don't add trailing slash in sprintf --- README.md | 2 +- src/routes.ml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 013255a..a6523bb 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ val my_fancy_route : unit -> (int -> 'a, 'a) Routes.path = val print_route : int -> string = # print_route 12;; -- : string = "user/12/add/" +- : string = "user/12/add" ``` ## Installation diff --git a/src/routes.ml b/src/routes.ml index b62b811..ff9bf4c 100644 --- a/src/routes.ml +++ b/src/routes.ml @@ -150,13 +150,13 @@ let rec route_pattern : type a b. (a, b) path -> PatternTrie.Key.t list = functi | Match (w, fmt) -> PatternTrie.Key.Match w :: route_pattern fmt | Conv (_, fmt) -> PatternTrie.Key.Capture :: route_pattern fmt -let rec ksprintf : type a b. (string -> b) -> (a, b) path -> a = +let rec ksprintf : type a b. (string list -> b) -> (a, b) path -> a = fun k -> function - | End -> k "" - | Match (w, fmt) -> ksprintf (fun s -> k @@ w ^ "/" ^ s) fmt - | Conv ({ to_; _ }, fmt) -> fun x -> ksprintf (fun rest -> k @@ to_ x ^ "/" ^ rest) fmt + | End -> k [] + | Match (w, fmt) -> ksprintf (fun s -> k @@ (w :: s)) fmt + | Conv ({ to_; _ }, fmt) -> fun x -> ksprintf (fun rest -> k @@ (to_ x :: rest)) fmt -let sprintf r = ksprintf (fun x -> x) (r ()) +let sprintf r = ksprintf (fun x -> String.concat "/" x) (r ()) let parse_route fmt handler params = let rec match_target : type a b. (a, b) path -> a -> string list -> b option =