debian-mirror-gitlab/spec/lib/banzai/pipeline/description_pipeline_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2016-04-02 18:10:28 +05:30
2023-04-23 21:23:45 +05:30
RSpec.describe Banzai::Pipeline::DescriptionPipeline, feature_category: :team_planning do
2020-06-23 00:09:42 +05:30
let_it_be(:project) { create(:project) }
2016-04-02 18:10:28 +05:30
def parse(html)
# When we pass HTML to Redcarpet, it gets wrapped in `p` tags...
# ...except when we pass it pre-wrapped text. Rabble rabble.
2016-11-03 12:29:30 +05:30
unwrap = !html.start_with?('<p ')
2016-04-02 18:10:28 +05:30
2020-06-23 00:09:42 +05:30
output = described_class.to_html(html, project: project)
2016-04-02 18:10:28 +05:30
2016-11-03 12:29:30 +05:30
output.gsub!(%r{\A<p dir="auto">(.*)</p>(.*)\z}, '\1\2') if unwrap
2016-04-02 18:10:28 +05:30
output
end
2019-03-02 22:35:43 +05:30
before do
stub_commonmark_sourcepos_disabled
end
2021-03-08 18:12:59 +05:30
it 'uses a limited allowlist' do
2016-04-02 18:10:28 +05:30
doc = parse('# Description')
expect(doc.strip).to eq 'Description'
end
%w(pre code img ol ul li).each do |elem|
it "removes '#{elem}' elements" do
act = "<#{elem}>Description</#{elem}>"
expect(parse(act).strip).to eq 'Description'
end
end
2016-11-03 12:29:30 +05:30
%w(b i strong em a ins del sup sub).each do |elem|
2016-04-02 18:10:28 +05:30
it "still allows '#{elem}' elements" do
exp = act = "<#{elem}>Description</#{elem}>"
expect(parse(act).strip).to eq exp
end
end
2016-11-03 12:29:30 +05:30
it "still allows 'p' elements" do
exp = act = "<p dir=\"auto\">Description</p>"
expect(parse(act).strip).to eq exp
end
2016-04-02 18:10:28 +05:30
end