Fix parsing error on URLs ending in ) with no path separator. e.g., http://example.com)

This commit is contained in:
Mark Felder 2021-07-07 16:52:16 -05:00
parent ec7475a7e2
commit 98947c5d53
3 changed files with 16 additions and 0 deletions

View file

@ -1,5 +1,11 @@
# Changelog
## 0.5.1 - 2021-07-07
### Fixed
- Parsing crash with URLs ending in unbalanced closed paren, no path separator, and no query parameters
## 0.5.0 - 2021-03-02
### Added

View file

@ -242,7 +242,9 @@ defmodule Linkify.Parser do
do: (trim_trailing_paren(trimmed) |> url?(nil) && :next) || :noop
defp parens_in_query(query), do: (is_nil(query) && :next) || :both
defp parens_found_path_separator(path) when is_nil(path), do: :next
defp parens_found_path_separator(path), do: (String.contains?(path, "/") && :next) || :both
defp parens_path_has_open_paren(path) when is_nil(path), do: :next
defp parens_path_has_open_paren(path), do: (String.contains?(path, "(") && :next) || :both
defp parens_check_balanced(trimmed) do

View file

@ -803,5 +803,13 @@ defmodule LinkifyTest do
assert Linkify.link(text) == expected
end
test "works with URLs ending in unbalanced closed paren, no path separator, and no query params" do
text = "http://example.com)"
expected = "<a href=\"http://example.com\">http://example.com</a>)"
assert Linkify.link(text) == expected
end
end
end