Skip to content

Commit bb60dd4

Browse files
committed
Add support for @ prefix on MentionFilter base_url
1 parent 4a16827 commit bb60dd4

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

lib/html_pipeline/node_filter/mention_filter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def link_to_mentioned_user(base_url, login)
115115
result[:mentioned_usernames] |= [login]
116116

117117
url = base_url.dup
118-
url << "/" unless %r{[/~]\z}.match?(url)
118+
excluded_prefixes = [%r{[/~]\z}, %r{[/@]\z}]
119+
url << "/" unless excluded_prefixes.any? { |excluded_prefix| excluded_prefix.match?(url) }
119120

120121
"<a href=\"#{url << login}\" class=\"user-mention\">" \
121122
"@#{login}" \

lib/html_pipeline/node_filter/team_mention_filter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def link_to_mentioned_team(base_url, org, team)
9494
result[:mentioned_teams] |= [team]
9595

9696
url = base_url.dup
97-
url << "/" unless %r{[/~]\z}.match?(url)
97+
excluded_prefixes = [%r{[/~]\z}, %r{[/@]\z}]
98+
url << "/" unless excluded_prefixes.any? { |excluded_prefix| excluded_prefix.match?(url) }
9899

99100
"<a href=\"#{url << org}/#{team}\" class=\"team-mention\">" \
100101
"@#{org}/#{team}" \

test/html_pipeline/node_filter/mention_filter_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ def test_base_url_slash_with_tilde
105105
)
106106
end
107107

108+
def test_base_url_slash_with_at
109+
body = "<p>Hi, @jch!</p>"
110+
link = '<a href="/@jch" class="user-mention">@jch</a>'
111+
112+
assert_equal(
113+
"<p>Hi, #{link}!</p>",
114+
@filter.call(body, context: @context.merge({ base_url: "/@" })),
115+
)
116+
end
117+
108118
def test_matches_usernames_in_body
109119
body = "@test how are you?"
110120

test/html_pipeline/node_filter/team_mention_filter_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ def test_base_url_slash_with_tilde
115115
)
116116
end
117117

118+
def test_base_url_slash_with_at
119+
body = "<p>Hi, @github/team!</p>"
120+
link = '<a href="/@github/team" class="team-mention">@github/team</a>'
121+
122+
assert_equal(
123+
"<p>Hi, #{link}!</p>",
124+
@filter.call(body, context: { base_url: "/@" }),
125+
)
126+
end
127+
118128
def test_multiple_team_mentions
119129
body = "<p>Hi, @github/whale and @github/donut!</p>"
120130
link_whale = '<a href="/github/whale" class="team-mention">@github/whale</a>'

0 commit comments

Comments
 (0)