Skip to content

Commit

Permalink
Fix autolinking of functions with / in name (#1228)
Browse files Browse the repository at this point in the history
Such as the case of Kernel.//2
  • Loading branch information
eksperimental committed Jul 18, 2020
1 parent d26ca71 commit 2d0fe21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ex_doc/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ defmodule ExDoc.Autolink do
defp url("mix " <> name, _mode, config), do: mix_task(name, config)

defp url(code, mode, config) do
case String.split(code, "/") do
[left, right] ->
case Regex.run(~r{^(.+)/(\d+)$}, code) do
[_, left, right] ->
with {:ok, arity} <- parse_arity(right) do
{kind, rest} = kind(left)

Expand All @@ -205,8 +205,8 @@ defmodule ExDoc.Autolink do
nil
end

[string] ->
case parse_module(string, mode) do
nil ->
case parse_module(code, mode) do
{:module, module} ->
module_url(module, config)

Expand Down
14 changes: 14 additions & 0 deletions test/ex_doc/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,20 @@ defmodule ExDoc.AutolinkTest do
assert_unchanged(~m"[Foo](#baz)", opts)
end

test "special case links" do
assert autolink(~m"`//2`") ==
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("//2")]}

assert autolink(~m"[division](`//2`)") ==
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}

assert autolink(~m"`Kernel.//2`") ==
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("Kernel.//2")]}

assert autolink(~m"[division](`Kernel.//2`)") ==
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
end

test "other link" do
assert_unchanged(~m"[`String`](foo.html)")
assert_unchanged(~m"[custom text](foo.html)")
Expand Down

0 comments on commit 2d0fe21

Please sign in to comment.