Skip to content

Commit 2d0fe21

Browse files
Fix autolinking of functions with / in name (#1228)
Such as the case of Kernel.//2
1 parent d26ca71 commit 2d0fe21

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/ex_doc/autolink.ex

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ defmodule ExDoc.Autolink do
185185
defp url("mix " <> name, _mode, config), do: mix_task(name, config)
186186

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

@@ -205,8 +205,8 @@ defmodule ExDoc.Autolink do
205205
nil
206206
end
207207

208-
[string] ->
209-
case parse_module(string, mode) do
208+
nil ->
209+
case parse_module(code, mode) do
210210
{:module, module} ->
211211
module_url(module, config)
212212

test/ex_doc/autolink_test.exs

+14
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ defmodule ExDoc.AutolinkTest do
216216
assert_unchanged(~m"[Foo](#baz)", opts)
217217
end
218218

219+
test "special case links" do
220+
assert autolink(~m"`//2`") ==
221+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("//2")]}
222+
223+
assert autolink(~m"[division](`//2`)") ==
224+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
225+
226+
assert autolink(~m"`Kernel.//2`") ==
227+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], [ast("Kernel.//2")]}
228+
229+
assert autolink(~m"[division](`Kernel.//2`)") ==
230+
{:a, [href: "https://hexdocs.pm/elixir/Kernel.html#//2"], ["division"]}
231+
end
232+
219233
test "other link" do
220234
assert_unchanged(~m"[`String`](foo.html)")
221235
assert_unchanged(~m"[custom text](foo.html)")

0 commit comments

Comments
 (0)