Trim extra spaces from search input.

pull/42/head
CJ Bryan and Derek Barnes 7 years ago
parent 5bbd950195
commit 66706c2939
  1. 5
      lib/explorer_web/controllers/chain_controller.ex
  2. 7
      test/explorer_web/controllers/chain_controller_test.exs

@ -9,7 +9,10 @@ defmodule ExplorerWeb.ChainController do
end
def search(conn, %{"q" => query}) do
case Resource.lookup(query) do
query
|> String.trim()
|> Resource.lookup()
|> case do
nil ->
conn
|> put_status(:not_found)

@ -85,6 +85,13 @@ defmodule ExplorerWeb.ChainControllerTest do
assert redirected_to(conn) == address_path(conn, :show, "en", address.hash)
end
test "finds an address by hash when there are extra spaces", %{conn: conn} do
address = insert(:address)
conn = get(conn, "en/search?q=#{address.hash} ")
assert redirected_to(conn) == address_path(conn, :show, "en", address.hash)
end
test "redirects to 404 when it finds nothing", %{conn: conn} do
conn = get(conn, "en/search?q=zaphod")
assert conn.status == 404

Loading…
Cancel
Save