Skip to content

Commit

Permalink
don't add trailing slash in sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed Jan 19, 2020
1 parent d3fdb5f commit d74e718
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ val my_fancy_route : unit -> (int -> 'a, 'a) Routes.path = <fun>
val print_route : int -> string = <fun>
# print_route 12;;
- : string = "user/12/add/"
- : string = "user/12/add"
```

## Installation
Expand Down
10 changes: 5 additions & 5 deletions src/routes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d74e718

Please sign in to comment.