Skip to content

Commit 8e34e47

Browse files
committed
Support ~login for MentionFilter and add more test for mentioned user.
1 parent 5feb0c1 commit 8e34e47

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/html/pipeline/@mention_filter.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@ def link_to_mention_info(text, info_url=nil)
125125

126126
def link_to_mentioned_user(login)
127127
result[:mentioned_usernames] |= [login]
128-
url = File.join(base_url, login)
129-
"<a href='#{url}' class='user-mention'>" +
128+
129+
if base_url.last == '~' && base_url.last(2) != '/~'
130+
base_url.prepend("/")
131+
else
132+
base_url << "/" unless base_url.last =~ /\/|~/
133+
end
134+
135+
"<a href='#{base_url << login}' class='user-mention'>" +
130136
"@#{login}" +
131137
"</a>"
132138
end
133139
end
134140
end
135-
end
141+
end

test/html/pipeline/mention_filter_test.rb

+28
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,34 @@ def test_links_to_more_info_when_info_url_given
7272
filter(body, '/', 'https://github.com/blog/821').to_html
7373
end
7474

75+
def test_base_url_slash
76+
body = "<p>Hi, @jch!</p>"
77+
link = "<a href=\"/jch\" class=\"user-mention\">@jch</a>"
78+
assert_equal "<p>Hi, #{link}!</p>",
79+
filter(body, '/').to_html
80+
end
81+
82+
def test_base_url_under_custom_route
83+
body = "<p>Hi, @jch!</p>"
84+
link = "<a href=\"/userprofile/jch\" class=\"user-mention\">@jch</a>"
85+
assert_equal "<p>Hi, #{link}!</p>",
86+
filter(body, '/userprofile').to_html
87+
end
88+
89+
def test_base_url_tilde
90+
body = "<p>Hi, @jch!</p>"
91+
link = "<a href=\"/~jch\" class=\"user-mention\">@jch</a>"
92+
assert_equal "<p>Hi, #{link}!</p>",
93+
filter(body, '~').to_html
94+
end
95+
96+
def test_base_url_slash_with_tilde
97+
body = "<p>Hi, @jch!</p>"
98+
link = "<a href=\"/~jch\" class=\"user-mention\">@jch</a>"
99+
assert_equal "<p>Hi, #{link}!</p>",
100+
filter(body, '/~').to_html
101+
end
102+
75103
MarkdownPipeline =
76104
HTML::Pipeline.new [
77105
HTML::Pipeline::MarkdownFilter,

0 commit comments

Comments
 (0)