gcanti / fp-ts-routing

A type-safe bidirectional routing library for TypeScript

Home Page:https://gcanti.github.io/fp-ts-routing/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URI encode pathname parts?

OliverJAsh opened this issue · comments

Should this library handle URI encoding of the pathname "parts" when formatting a route, or should that be handled by the user?

Currently, query params are URI encoded, but pathname parts are not:

E.g.

const searchQueryQueryParam = query(t.interface({ q: t.string })).then(end);
const searchQuery = lit("search")
  .then(str("query"))
  .then(end);

const formatRoute = <A extends object>(match: Match<A>) => (route: A): string =>
  match.formatter.run(RouteBase.empty, route).toString();

console.log(formatRoute(searchQueryQueryParam)({ q: "foo bar baz" })); // => "/?q=foo%20bar%20baz"
console.log(formatRoute(searchQuery)({ query: "foo bar baz" })); // => "/search/foo bar baz"

Thanks @OliverJAsh, looks like a bug