Skip to content

Commit

Permalink
Escape signature. (#1226)
Browse files Browse the repository at this point in the history
It was breaking HTML validation when function name had special HTML chars that
needs to be escaped. such as `<`
  • Loading branch information
eksperimental committed Jul 18, 2020
1 parent 53c46e2 commit 5fed479
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ex_doc/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ defmodule ExDoc.Autolink do
|> Macro.to_string()
|> Code.format_string!(line_length: 80)
|> IO.iodata_to_binary()
|> T.h()

name = typespec_name(ast)
{name, rest} = split_name(string, name)

name <> do_typespec(rest, config)
end

Expand Down
5 changes: 5 additions & 0 deletions test/ex_doc/autolink_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ defmodule ExDoc.AutolinkTest do
assert typespec(quote(do: t() :: :sets.set())) ==
~s[t() :: <a href=\"http://www.erlang.org/doc/man/sets.html#type-set\">:sets.set</a>()]
end

test "escape special HTML characters" do
assert typespec(quote(do: term() < term() :: boolean())) ==
~s[<a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>() &lt; <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">term</a>() :: <a href="https://hexdocs.pm/elixir/typespecs.html#built-in-types">boolean</a>()]
end
end

test "warnings" do
Expand Down

0 comments on commit 5fed479

Please sign in to comment.