Skip to content

~p sigil does not work with non-ascii characters #6524

@aeons

Description

@aeons

Environment

  • Elixir version (elixir -v): 1.19.1
  • Phoenix version (mix deps): 1.8.1
  • Operating system: macOS 26

Actual behavior

With a route containing a unicode character, the ~p sigil will warn that the route does not exist.

# in lib/unicode_verified_routes_web/router.ex
    get("/ø", HomeController, :index)
# in eg. a template
<a href={~p""}>Ø</a>
$ mix compile
    warning: no route path for UnicodeVerifiedRoutesWeb.Router matches "/ø"
    │
  1 │ <a href={~p"/ø"}>Ø</a>
    │ ~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ lib/unicode_verified_routes_web/controllers/page_html/home.html.heex:1: UnicodeVerifiedRoutesWeb.PageHTML.home/1
Reproduction code. However the compile warning is not shown when running as .exs
Application.put_env(:phoenix, :json_library, JSON)

Application.put_env(:sample, SamplePhoenix.Endpoint,
  http: [ip: {127, 0, 0, 1}, port: 5001],
  server: true,
  adapter: Bandit.PhoenixAdapter,
  secret_key_base: String.duplicate("a", 64)
)

Mix.install([
  {:bandit, "~> 1.8"},
  {:phoenix, "~> 1.8"}
])

defmodule SamplePhoenix.SampleController do
  use Phoenix.Controller, formats: [:html, :json]

  use Phoenix.VerifiedRoutes,
    endpoint: SamplePhoenix.Endpoint,
    router: Router

  def index(conn, _) do
    send_resp(conn, 200, ~p"")
  end
end

defmodule Router do
  use Phoenix.Router

  pipeline :browser do
    plug(:accepts, ["html"])
  end

  scope "/", SamplePhoenix do
    pipe_through(:browser)

    get("/", SampleController, :index)
    get("/ø", SampleController, :index)

    # Prevent a horrible error because ErrorView is missing
    get("/favicon.ico", SampleController, :index)
  end
end

defmodule SamplePhoenix.Endpoint do
  use Phoenix.Endpoint, otp_app: :sample
  plug(Router)
end

{:ok, _} = Supervisor.start_link([SamplePhoenix.Endpoint], strategy: :one_for_one)
Process.sleep(:infinity)

Expected behavior

That the route would be detected and work as a regular route would.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions