2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Banzai::Filter::OutputSafety do
|
2019-07-07 11:18:12 +05:30
|
|
|
subject do
|
|
|
|
Class.new do
|
|
|
|
include Banzai::Filter::OutputSafety
|
|
|
|
end.new
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:content) { '<pre><code>foo</code></pre>' }
|
|
|
|
|
|
|
|
context 'when given HTML is safe' do
|
|
|
|
let(:html) { content.html_safe }
|
|
|
|
|
|
|
|
it 'returns safe HTML' do
|
|
|
|
expect(subject.escape_once(html)).to eq(html)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when given HTML is not safe' do
|
|
|
|
let(:html) { content }
|
|
|
|
|
|
|
|
it 'returns escaped HTML' do
|
|
|
|
expect(subject.escape_once(html)).to eq(ERB::Util.html_escape_once(html))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|