It seems that Plug.Conn.Query.encode() converts the space character to “+”. From what I can tell, that is an old (sub) standard for URL param encoding.
%20 is the correct replacement according to https://tools.ietf.org/html/rfc3986
Does anyone know why this is the way it is in Plug?
You might use
:http_uri.encode/1 to escape
" " with
Plug.Conn.Query.encode/1 behaves this way because of
URI.encode_www_form/1, which intentionally replaces
+, which is valid in
iex> URI.encode_www_form(" ")
iex> :http_uri.encode(" ")
There is already mentioned URI module with lots of functions to work with. One of them is https://hexdocs.pm/elixir/URI.html#encode/2 which does percent-escape.