Linkify.Parser.restore_stripped_symbols/3 must always return iodata

This commit is contained in:
Sergey Suprunenko 2020-09-10 20:15:49 +02:00
parent 7005cda9e4
commit c4b4cb95fb
No known key found for this signature in database
GPG key ID: 5DCA7D1BE3914F9C

View file

@ -175,7 +175,7 @@ defmodule Linkify.Parser do
url ->
link = link_url(url, opts)
restore_stripped_symbols(buffer, url, link, opts)
restore_stripped_symbols(buffer, url, link)
end
else
:nomatch
@ -344,19 +344,18 @@ defmodule Linkify.Parser do
{:cont, {buffer, user_acc}}
{link, user_acc} ->
{:halt, {restore_stripped_symbols(buffer, str, link, opts), user_acc}}
{:halt, {restore_stripped_symbols(buffer, str, link), user_acc}}
link ->
{:halt, {restore_stripped_symbols(buffer, str, link, opts), user_acc}}
{:halt, {restore_stripped_symbols(buffer, str, link), user_acc}}
end
end
defp restore_stripped_symbols(buffer, buffer, link, _), do: link
defp restore_stripped_symbols(buffer, buffer, link), do: link
defp restore_stripped_symbols(buffer, stripped_buffer, link, opts) do
defp restore_stripped_symbols(buffer, stripped_buffer, link) do
buffer
|> String.split(stripped_buffer)
|> Enum.intersperse(link)
|> if(opts[:iodata], do: &Enum.reject(&1, fn el -> el == "" end), else: &Enum.join(&1)).()
end
end