Sha256: 48737c617e9cc448f15843c8b2f579879bd4995bdde707d633f66dcc31f3ad1e

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

RSpec.describe 'Sanitize rendering', type: :render do
  it 'parses sanitized script' do
    # Default in fast_haml
    expect(render_string('&= "hello<p>unescape</p>world"')).to eq("hello&lt;p&gt;unescape&lt;/p&gt;world\n")
    expect(render_string(<<HAML)).to eq("<span>\nhello&lt;p&gt;unescape&lt;/p&gt;world\n</span>\n")
%span
  &= "hello<p>unescape</p>world"
HAML
  end

  it 'ignores single sanitize mark' do
    expect(render_string('& <p>hello</p>')).to eq("<p>hello</p>\n")
    expect(render_string('%span& <p>hello</p>')).to eq("<span><p>hello</p></span>\n")
  end

  it 'parses == syntax' do
    expect(render_string('&== =<p>hello</p>')).to eq("=<p>hello</p>\n")
    expect(render_string('%span&== =<p>hello</p>')).to eq("<span>=<p>hello</p></span>\n")
  end

  context 'with preserve' do
    it 'ignores preserve mark' do
      expect(render_string('&~ "<p>hello</p>"')).to eq("&lt;p&gt;hello&lt;/p&gt;\n")
      expect(render_string('%span&~ "<p>hello</p>"')).to eq("<span>&lt;p&gt;hello&lt;/p&gt;</span>\n")
    end
  end

  context 'without Ruby code' do
    it 'raises error' do
      expect { render_string('%span&=') }.to raise_error(FastHaml::SyntaxError)
      expect { render_string('&=') }.to raise_error(FastHaml::SyntaxError)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fast_haml-0.1.10 spec/render/sanitize_spec.rb
fast_haml-0.1.9 spec/render/sanitize_spec.rb
fast_haml-0.1.8 spec/render/sanitize_spec.rb
fast_haml-0.1.7 spec/render/sanitize_spec.rb
fast_haml-0.1.6 spec/render/sanitize_spec.rb
fast_haml-0.1.5 spec/render/sanitize_spec.rb
fast_haml-0.1.4 spec/render/sanitize_spec.rb
fast_haml-0.1.3 spec/render/sanitize_spec.rb
fast_haml-0.1.2 spec/render/sanitize_spec.rb
fast_haml-0.1.1 spec/render/sanitize_spec.rb
fast_haml-0.1.0 spec/render/sanitize_spec.rb