Skip to content

Commit

Permalink
Merge pull request #411 from jeremysmithco/mention_filter-base_url-at…
Browse files Browse the repository at this point in the history
…-prefix

Add support for @ prefix on MentionFilter base_url
  • Loading branch information
gjtorikian authored Aug 4, 2024
2 parents 4a16827 + dbbc46a commit ba6ec7f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/html_pipeline/node_filter/mention_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def link_to_mentioned_user(base_url, login)
result[:mentioned_usernames] |= [login]

url = base_url.dup
url << "/" unless %r{[/~]\z}.match?(url)
excluded_prefixes = %r{[/(?:~|@]\z}
url << "/" unless excluded_prefixes.match?(url)

"<a href=\"#{url << login}\" class=\"user-mention\">" \
"@#{login}" \
Expand Down
3 changes: 2 additions & 1 deletion lib/html_pipeline/node_filter/team_mention_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def link_to_mentioned_team(base_url, org, team)
result[:mentioned_teams] |= [team]

url = base_url.dup
url << "/" unless %r{[/~]\z}.match?(url)
excluded_prefixes = %r{[/(?:~|@]\z}
url << "/" unless excluded_prefixes.match?(url)

"<a href=\"#{url << org}/#{team}\" class=\"team-mention\">" \
"@#{org}/#{team}" \
Expand Down
10 changes: 10 additions & 0 deletions test/html_pipeline/node_filter/mention_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def test_base_url_slash_with_tilde
)
end

def test_base_url_slash_with_at
body = "<p>Hi, @jch!</p>"
link = '<a href="/@jch" class="user-mention">@jch</a>'

assert_equal(
"<p>Hi, #{link}!</p>",
@filter.call(body, context: @context.merge({ base_url: "/@" })),
)
end

def test_matches_usernames_in_body
body = "@test how are you?"

Expand Down
10 changes: 10 additions & 0 deletions test/html_pipeline/node_filter/team_mention_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ def test_base_url_slash_with_tilde
)
end

def test_base_url_slash_with_at
body = "<p>Hi, @github/team!</p>"
link = '<a href="/@github/team" class="team-mention">@github/team</a>'

assert_equal(
"<p>Hi, #{link}!</p>",
@filter.call(body, context: { base_url: "/@" }),
)
end

def test_multiple_team_mentions
body = "<p>Hi, @github/whale and @github/donut!</p>"
link_whale = '<a href="/github/whale" class="team-mention">@github/whale</a>'
Expand Down

0 comments on commit ba6ec7f

Please sign in to comment.