From ab58d24c038e4de51dfb9913b88dbca1fc67d53d Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 21 Feb 2019 14:30:59 +0700 Subject: [PATCH] do not match hashtags consisting entirely of numbers --- lib/auto_linker/parser.ex | 7 +++++-- test/auto_linker_test.exs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex index c675bb1..74d50ee 100644 --- a/lib/auto_linker/parser.ex +++ b/lib/auto_linker/parser.ex @@ -362,8 +362,11 @@ defmodule AutoLinker.Parser do def match_hashtag(buffer) do case Regex.run(@match_hashtag, buffer, capture: [:tag]) do - [hashtag] -> hashtag - _ -> nil + [hashtag] -> + if Regex.match?(~r/#\d+$/, hashtag), do: nil, else: hashtag + + _ -> + nil end end diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs index ad26d81..49a592b 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -152,6 +152,18 @@ defmodule AutoLinkerTest do ) == expected end + test "must have non-numbers" do + expected = "#1ok #42 #7" + + assert AutoLinker.link("#1ok #42 #7", + hashtag: true, + hashtag_prefix: "/t/", + class: false, + rel: false, + new_window: false + ) == expected + end + test "do not turn urls with hashes into hashtags" do text = "google.com#test #test google.com/#test #tag"