Browse Source

do not match hashtags consisting entirely of numbers

merge-requests/5/head
Egor Kislitsyn 5 years ago
parent
commit
ab58d24c03
2 changed files with 17 additions and 2 deletions
  1. +5
    -2
      lib/auto_linker/parser.ex
  2. +12
    -0
      test/auto_linker_test.exs

+ 5
- 2
lib/auto_linker/parser.ex View File

@ -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


+ 12
- 0
test/auto_linker_test.exs View File

@ -152,6 +152,18 @@ defmodule AutoLinkerTest do
) == expected
end
test "must have non-numbers" do
expected = "<a href=\"/t/1ok\">#1ok</a> #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"


Loading…
Cancel
Save