Fix parsing error on URLs ending in ) with no path separator. e.g., http://example.com)
This commit is contained in:
parent
ec7475a7e2
commit
98947c5d53
3 changed files with 16 additions and 0 deletions
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# 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
|
## 0.5.0 - 2021-03-02
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -242,7 +242,9 @@ defmodule Linkify.Parser do
|
||||||
do: (trim_trailing_paren(trimmed) |> url?(nil) && :next) || :noop
|
do: (trim_trailing_paren(trimmed) |> url?(nil) && :next) || :noop
|
||||||
|
|
||||||
defp parens_in_query(query), do: (is_nil(query) && :next) || :both
|
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_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_path_has_open_paren(path), do: (String.contains?(path, "(") && :next) || :both
|
||||||
|
|
||||||
defp parens_check_balanced(trimmed) do
|
defp parens_check_balanced(trimmed) do
|
||||||
|
|
|
@ -803,5 +803,13 @@ defmodule LinkifyTest do
|
||||||
|
|
||||||
assert Linkify.link(text) == expected
|
assert Linkify.link(text) == expected
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue