require 'rails_helper'
describe BaseMarkdownRenderer do
let(:renderer) { described_class.new }
def render_markdown(markdown)
doc = CommonMarker.render_doc(markdown, :DEFAULT)
renderer.render(doc)
end
describe '#image' do
context 'when image has a height' do
it 'renders the img tag with the correct attributes' do
markdown = ''
expect(render_markdown(markdown)).to include('
')
end
end
context 'when image has a width' do
it 'renders the img tag with the correct attributes' do
markdown = ''
expect(render_markdown(markdown)).to include(
'
'
)
end
end
context 'when the sizing param contains an attribute-injection payload' do
it 'drops the malicious height value' do
markdown = ')'
rendered = render_markdown(markdown)
expect(rendered).not_to include('style=')
expect(rendered).not_to include('onmouseover="')
end
it 'drops the malicious width value' do
markdown = ')'
rendered = render_markdown(markdown)
expect(rendered).not_to include('style=')
expect(rendered).not_to include('onmouseover="')
end
end
context 'when image does not have a height' do
it 'renders the img tag without the height attribute' do
markdown = ''
expect(render_markdown(markdown)).to include('
')
end
end
context 'when image has an invalid URL' do
it 'renders the img tag without crashing' do
markdown = ''
expect { render_markdown(markdown) }.not_to raise_error
end
end
end
end