Skip to content

Commit

Permalink
Don't crash on code blocks like "A.b.C", closes #1285
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Oct 12, 2020
1 parent a4a497d commit c23302a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/ex_doc/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,18 @@ defmodule ExDoc.Autolink do

defp do_parse_module(string) do
case Code.string_to_quoted(string, warn_on_unnecessary_quotes: false) do
{:ok, module} when is_atom(module) -> {:module, module}
{:ok, {:__aliases__, _, parts}} -> {:module, Module.concat(parts)}
_ -> :error
{:ok, module} when is_atom(module) ->
{:module, module}

{:ok, {:__aliases__, _, parts}} ->
if Enum.all?(parts, &is_atom/1) do
{:module, Module.concat(parts)}
else
:error
end

_ ->
:error
end
end

Expand Down
1 change: 1 addition & 0 deletions test/ex_doc/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule ExDoc.AutolinkTest do
test "unknown module" do
assert_unchanged("Unknown")
assert_unchanged(":unknown")
assert_unchanged("A.b.C")
end

test "project-local module" do
Expand Down

0 comments on commit c23302a

Please # to comment.