Skip to content
Snippets Groups Projects
Commit 53aff128 authored by Eric Eastwood's avatar Eric Eastwood
Browse files

Fix first line markdown helper for user profile activity stream

parent edf29b57
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -165,8 +165,8 @@ module EventsHelper
 
sanitize(
text,
tags: %w(a img b pre code p span),
attributes: Rails::Html::WhiteListSanitizer.allowed_attributes + ['style']
tags: %w(a img gl-emoji b pre code p span),
attributes: Rails::Html::WhiteListSanitizer.allowed_attributes + ['style', 'data-name', 'data-unicode-version', 'data-fallback-src', 'data-fallback-sprite-class']
)
end
 
Loading
Loading
Loading
Loading
@@ -172,7 +172,7 @@ module GitlabMarkdownHelper
# text hasn't already been truncated, then append "..." to the node contents
# and return true. Otherwise return false.
def truncate_if_block(node, truncated)
if node.element? && node.description.block? && !truncated
if node.element? && node&.description&.block? && !truncated
node.inner_html = "#{node.inner_html}..." if node.next_sibling
true
else
Loading
Loading
Loading
Loading
@@ -152,9 +152,8 @@ describe GitlabMarkdownHelper do
end
 
describe '#first_line_in_markdown' do
let(:text) { "@#{user.username}, can you look at this?\nHello world\n"}
it 'truncates Markdown properly' do
text = "@#{user.username}, can you look at this?\nHello world\n"
actual = first_line_in_markdown(text, 100, project: project)
 
doc = Nokogiri::HTML.parse(actual)
Loading
Loading
@@ -169,6 +168,23 @@ describe GitlabMarkdownHelper do
 
expect(doc.content).to eq "@#{user.username}, can you look at this?..."
end
it 'truncates Markdown with emoji properly' do
text = "foo :wink:\nbar :grinning:"
actual = first_line_in_markdown(text, 100, project: project)
doc = Nokogiri::HTML.parse(actual)
# Make sure we didn't create invalid markup
# But also account for the 2 errors caused by the unknown `gl-emoji` elements
expect(doc.errors.length).to eq(2)
expect(doc.css('gl-emoji').length).to eq(2)
expect(doc.css('gl-emoji')[0].attr('data-name')).to eq 'wink'
expect(doc.css('gl-emoji')[1].attr('data-name')).to eq 'grinning'
expect(doc.content).to eq "foo 😉\nbar 😀"
end
end
 
describe '#cross_project_reference' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment