2016-02-03 17:19:54 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Banzai::Pipeline::DescriptionPipeline do
|
|
|
|
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-09-11 12:08:09 -04:00
|
|
|
unwrap = !html.start_with?('<p ')
|
2016-02-03 17:19:54 -05:00
|
|
|
|
|
|
|
output = described_class.to_html(html, project: spy)
|
|
|
|
|
2016-09-11 12:08:09 -04:00
|
|
|
output.gsub!(%r{\A<p dir="auto">(.*)</p>(.*)\z}, '\1\2') if unwrap
|
2016-02-03 17:19:54 -05:00
|
|
|
|
|
|
|
output
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses a limited whitelist' do
|
|
|
|
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-09-11 12:08:09 -04:00
|
|
|
%w(b i strong em a ins del sup sub).each do |elem|
|
2016-02-03 17:19:54 -05:00
|
|
|
it "still allows '#{elem}' elements" do
|
|
|
|
exp = act = "<#{elem}>Description</#{elem}>"
|
|
|
|
|
|
|
|
expect(parse(act).strip).to eq exp
|
|
|
|
end
|
|
|
|
end
|
2016-09-11 12:08:09 -04:00
|
|
|
|
|
|
|
it "still allows 'p' elements" do
|
|
|
|
exp = act = "<p dir=\"auto\">Description</p>"
|
|
|
|
|
|
|
|
expect(parse(act).strip).to eq exp
|
|
|
|
end
|
2016-02-03 17:19:54 -05:00
|
|
|
end
|