Commit a7b0ee3f authored by Stan Hu's avatar Stan Hu

Fix cases where Markdown did not render links in activity feed

HTML would be stripped in `truncate_if_block` when a comment had multiple lines
and the first wasn't long enough to be truncated. The use of `node.content` would
strip all HTML tags. Using `node.inner_html` retains these tags and puts the
"..." in between paragraph tags.

Closes #2586
parent 03fd5919
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.0.1 v 8.0.1
- Fix cases where Markdown did not render links in activity feed (Stan Hu)
- Improve CI migration procedure and documentation - Improve CI migration procedure and documentation
v 8.0.0 v 8.0.0
......
...@@ -165,7 +165,7 @@ module GitlabMarkdownHelper ...@@ -165,7 +165,7 @@ module GitlabMarkdownHelper
# and return true. Otherwise return false. # and return true. Otherwise return false.
def truncate_if_block(node, truncated) def truncate_if_block(node, truncated)
if node.element? && node.description.block? && !truncated if node.element? && node.description.block? && !truncated
node.content = "#{node.content}..." if node.next_sibling node.inner_html = "#{node.inner_html}..." if node.next_sibling
true true
else else
truncated truncated
......
...@@ -146,4 +146,24 @@ describe GitlabMarkdownHelper do ...@@ -146,4 +146,24 @@ describe GitlabMarkdownHelper do
expect(random_markdown_tip).to eq 'Random tip' expect(random_markdown_tip).to eq 'Random tip'
end end
end end
describe '#first_line_in_markdown' do
let(:text) { "@#{user.username}, can you look at this?\nHello world\n"}
it 'truncates Markdown properly' do
actual = first_line_in_markdown(text, 100, project: project)
doc = Nokogiri::HTML.parse(actual)
# Make sure we didn't create invalid markup
expect(doc.errors).to be_empty
# Leading user link
expect(doc.css('a').length).to eq(1)
expect(doc.css('a')[0].attr('href')).to eq user_path(user)
expect(doc.css('a')[0].text).to eq "@#{user.username}"
expect(doc.content).to eq "@#{user.username}, can you look at this?..."
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment