From 3599ccf7593f25ef6b7e4b711d420a6fc998c72a Mon Sep 17 00:00:00 2001 From: tusooa Date: Sun, 25 Dec 2022 20:37:01 -0500 Subject: [PATCH] Do not break hashtag at zwnj --- lib/linkify/parser.ex | 2 +- test/linkify_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/linkify/parser.ex b/lib/linkify/parser.ex index 233c681..af5afef 100644 --- a/lib/linkify/parser.ex +++ b/lib/linkify/parser.ex @@ -15,7 +15,7 @@ defmodule Linkify.Parser do @get_scheme_host ~r{^\W*(?https?:\/\/)?(?:[^@\n]+\\w@)?(?[^:#~\/\n?]+)}u - @match_hashtag ~r/^(?\#[[:word:]_]*[[:alpha:]_·][[:word:]_·\p{M}]*)/u + @match_hashtag ~r/^(?\#[[:word:]_]*[[:alpha:]_·\x{200c}][[:word:]_·\p{M}\x{200c}]*)/u @match_skipped_tag ~r/^(?(a|code|pre)).*>*/ diff --git a/test/linkify_test.exs b/test/linkify_test.exs index 1abca5f..8a9ace4 100644 --- a/test/linkify_test.exs +++ b/test/linkify_test.exs @@ -555,6 +555,18 @@ defmodule LinkifyTest do hashtag_prefix: "https://example.com/tag/" ) == expected end + + test "ZWNJ does not break up hashtags" do + text = "#ساٴين‌س" + + expected = "#ساٴين‌س" + + assert Linkify.link(text, + rel: false, + hashtag: true, + hashtag_prefix: "https://example.com/tag/" + ) == expected + end end describe "links" do