Commit f7580d52 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Fix rendering of scoped labels in todos

Add data-html and <i> to whitelist in first_line_in_markdown.
We need this tag and attribute to properly render scoped labels.
parent d0713e85
......@@ -79,7 +79,7 @@ module MarkupHelper
md = markdown_field(object, attribute, options.merge(post_process: false))
return unless md.present?
tags = %w(a gl-emoji b pre code p span)
tags = %w(a gl-emoji b strong i em pre code p span)
tags << 'img' if options[:allow_images]
text = truncate_visible(md, max_chars || md.length)
......@@ -88,7 +88,7 @@ module MarkupHelper
text,
tags: tags,
attributes: Rails::Html::WhiteListSanitizer.allowed_attributes +
%w(style data-src data-name data-unicode-version data-iid data-project-path data-mr-title)
%w(style data-src data-name data-unicode-version data-iid data-project-path data-mr-title data-html)
)
# since <img> tags are stripped, this can leave empty <a> tags hanging around
......@@ -233,7 +233,7 @@ module MarkupHelper
def strip_empty_link_tags(text)
scrubber = Loofah::Scrubber.new do |node|
node.remove if node.name == 'a' && node.content.blank?
node.remove if node.name == 'a' && node.children.empty?
end
sanitize text, scrubber: scrubber
......
---
title: Fix scoped labels rendering in To-Do List
merge_request: 26146
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe MarkupHelper do
let(:project) { create(:project, :public) }
describe '#first_line_in_markdown' do
context 'with scoped label references' do
let(:label) { create(:label, title: 'key::some name', project: project) }
before do
stub_licensed_features(scoped_labels: true)
end
it 'shows proper tooltip and documentation link' do
note = build(:note, note: label.to_reference, project: project)
result = first_line_in_markdown(note, :note, nil, project: project)
doc = Nokogiri::HTML.parse(result)
expect(doc.css('.gl-label-link')[0].attr('data-html')).to eq('true')
expect(doc.css('a .fa-question-circle').length).to eq(1)
end
end
end
end
......@@ -531,8 +531,10 @@ describe MarkupHelper do
it 'preserves style attribute for a label that can be accessed by current_user' do
project = create(:project, :public)
label = create_and_format_label(project)
expect(create_and_format_label(project)).to match(/span class=.*style=.*/)
expect(label).to match(/span class=.*style=.*/)
expect(label).to include('data-html="true"')
end
it 'does not style a label that can not be accessed by current_user' do
......@@ -544,6 +546,15 @@ describe MarkupHelper do
end
end
it 'keeps whitelisted tags' do
html = '<a><i></i></a> <strong>strong</strong><em>em</em><b>b</b>'
object = create_object(html)
result = first_line_in_markdown(object, attribute, 100, project: project)
expect(result).to include(html)
end
it 'truncates Markdown properly' do
object = create_object("@#{user.username}, can you look at this?\nHello world\n")
actual = first_line_in_markdown(object, attribute, 100, project: project)
......
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