fsbolero / Bolero

Bolero brings Blazor to F# developers with an easy to use Model-View-Update architecture, HTML combinators, hot reloaded templates, type-safe endpoints, advanced routing and remoting capabilities, and more.
https://fsbolero.io
Apache License 2.0
1.06k stars 54 forks source link

[Suggestion] URL decode path by default router #135

Closed kos59125 closed 4 years ago

kos59125 commented 4 years ago

Problem

Suppose router:Router<Route, _, _> is generated by Router.infer:

type Route =
   | [<EndPoint("/")>] Default
   | [<EndPoint("/{value}")>] Value of value:string

type Message =
   | SetPage of Route

type Model = { Page: Route }

let router = Router.infer SetPage (fun model -> model.Page)

When users access to non-ASCII endpoint such as /日本語, the passed URL path to Value endpoint may be URL-encoded as /%E6%97%A5%E6%9C%AC%E8%AA%9E by their web browser. It is not easy to use because I need to decode every time when I use URL path parameter.

let update message model =
   match message with
   | SetPage(page) -> { model with Page = page }

let view model dispatch =
   AppTemplate()
      .ContentsByPage(
         Html.cond model.Page <| function
            | Default -> (* ... *)
            | Value(value) -> (* value is URL encoded here *)  
      )

When an encoded path parameter is referred in update function via message and passed to remote server without explicit decode on client-side, the remote server will receive URL-encoded string in JSON and it could be the cause of a bug.

Suggestion

My suggestion is that the passed URL paths by router generated by Router.infer are always URL-decoded. I think it is tough task to make a custom router to avoid that problem.

Tarmil commented 4 years ago

Yes, this is a reasonable feature to add. Even more so considering that Blazor's routing does it.