From 94aeffd22712d6f251d3669db8e650c8f6d9cdab Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 30 Dec 2021 19:41:30 +0000 Subject: [PATCH 1/3] Fix hashtag parsing at the end of lines --- lib/linkify/parser.ex | 10 ++++++++-- test/linkify_test.exs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index f6df7a3..8a6296e 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -94,13 +94,19 @@ defmodule Linkify.Parser do ) do {buffer, user_acc} = link(buffer, opts, user_acc) - case Regex.run(@match_skipped_tag, text, capture: [:tag]) do + buffer = + case buffer do + [_, _, _] -> Enum.join(buffer) + _ -> buffer + end + + case Regex.run(@match_skipped_tag, buffer, capture: [:tag]) do [tag] -> text = String.trim_leading(text, tag) do_parse({text, user_acc}, opts, {"", accumulate(acc, buffer, "<#{tag}"), :skip}) nil -> - do_parse({text, user_acc}, opts, {"<", acc, {:open, 1}}) + do_parse({text, user_acc}, opts, {"<", accumulate(acc, buffer, ""), {:open, 1}}) end end diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 5f01fdb..126e0ea 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -179,6 +179,32 @@ defmodule LinkifyTest do assert MapSet.to_list(tags) == ["#hello", "#world"] + text = "#justOne" + + {result_text, %{tags: _tags}} = + Linkify.link_map(text, %{tags: MapSet.new()}, + hashtag: true, + hashtag_handler: handler, + hashtag_prefix: "https://example.com/user/", + rel: false + ) + + assert result_text == + "#justOne" + + text = "#justOne." + + {result_text, %{tags: _tags}} = + Linkify.link_map(text, %{tags: MapSet.new()}, + hashtag: true, + hashtag_handler: handler, + hashtag_prefix: "https://example.com/user/", + rel: false + ) + + assert result_text == + "#justOne." + text = "#cofe
Source" {_result_text, %{tags: tags}} = From b6f644545f188609673e796db42c54a1fee8d3b8 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 30 Dec 2021 19:42:50 +0000 Subject: [PATCH 2/3] Bump version --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index fa0ce65..b8efbe3 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule Linkify.Mixfile do use Mix.Project - @version "0.5.1" + @version "0.5.2" def project do [ From 2567e2c1073fa371fd26fd66dfa5bc77b6919c16 Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Thu, 30 Dec 2021 19:46:42 +0000 Subject: [PATCH 3/3] add bare whitespace test --- test/linkify_test.exs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 126e0ea..fb7f5f1 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -205,6 +205,19 @@ defmodule LinkifyTest do assert result_text == "#justOne." + text = "#justOne " + + {result_text, %{tags: _tags}} = + Linkify.link_map(text, %{tags: MapSet.new()}, + hashtag: true, + hashtag_handler: handler, + hashtag_prefix: "https://example.com/user/", + rel: false + ) + + assert result_text == + "#justOne " + text = "#cofe
Source" {_result_text, %{tags: tags}} =