Commit 8da519a8 authored by Sean McGivern's avatar Sean McGivern

Merge branch '207462-scoped-labels-rendering-is-broken-in-todos' into 'master'

Fix scoped labels rendering in Todos

See merge request gitlab-org/gitlab!26146
parents 859681c6 f7580d52
...@@ -79,7 +79,7 @@ module MarkupHelper ...@@ -79,7 +79,7 @@ module MarkupHelper
md = markdown_field(object, attribute, options.merge(post_process: false)) md = markdown_field(object, attribute, options.merge(post_process: false))
return unless md.present? 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] tags << 'img' if options[:allow_images]
text = truncate_visible(md, max_chars || md.length) text = truncate_visible(md, max_chars || md.length)
...@@ -88,7 +88,7 @@ module MarkupHelper ...@@ -88,7 +88,7 @@ module MarkupHelper
text, text,
tags: tags, tags: tags,
attributes: Rails::Html::WhiteListSanitizer.allowed_attributes + 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 # since <img> tags are stripped, this can leave empty <a> tags hanging around
...@@ -233,7 +233,7 @@ module MarkupHelper ...@@ -233,7 +233,7 @@ module MarkupHelper
def strip_empty_link_tags(text) def strip_empty_link_tags(text)
scrubber = Loofah::Scrubber.new do |node| 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 end
sanitize text, scrubber: scrubber 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 ...@@ -531,8 +531,10 @@ describe MarkupHelper do
it 'preserves style attribute for a label that can be accessed by current_user' do it 'preserves style attribute for a label that can be accessed by current_user' do
project = create(:project, :public) 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 end
it 'does not style a label that can not be accessed by current_user' do it 'does not style a label that can not be accessed by current_user' do
...@@ -544,6 +546,15 @@ describe MarkupHelper do ...@@ -544,6 +546,15 @@ describe MarkupHelper do
end end
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 it 'truncates Markdown properly' do
object = create_object("@#{user.username}, can you look at this?\nHello world\n") object = create_object("@#{user.username}, can you look at this?\nHello world\n")
actual = first_line_in_markdown(object, attribute, 100, project: project) 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