From 98947c5d5331c175c9bd4d98bd17c7db40f9c6eb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 7 Jul 2021 16:52:16 -0500 Subject: [PATCH] Fix parsing error on URLs ending in ) with no path separator. e.g., http://example.com) --- CHANGELOG.md | 6 ++++++ lib/linkify/parser.ex | 2 ++ test/linkify_test.exs | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b9dcd1..54ce609 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 8102d9e..f6df7a3 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -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 diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 6da502f..5f01fdb 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -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 = "http://example.com)" + + assert Linkify.link(text) == expected + end end end