Sha256: 68c7d501ece629cf87baf04119d9c999ab845c0c3fc369c0066e1c80ccc4db00

Contents?: true

Size: 1.19 KB

Versions: 31

Compression:

Stored size: 1.19 KB

Contents

# Rack 1.0 does not allow string subclass body. This does not play well with our ActiveSupport::SafeBuffer.
# The next release of Rack will be allowing string subclass body - http://github.com/rack/rack/commit/de668df02802a0335376a81ba709270e43ba9d55
# TODO : Remove this monkey patch after the next release of Rack

module RackLintPatch
  module AllowStringSubclass
    def self.included(base)
      base.send :alias_method, :each, :each_with_hack
    end

    def each_with_hack
      @closed = false

      @body.each { |part|
        assert("Body yielded non-string value #{part.inspect}") {
          part.kind_of?(String)
        }
        yield part
      }

      if @body.respond_to?(:to_path)
        assert("The file identified by body.to_path does not exist") {
          ::File.exist? @body.to_path
        }
      end
    end
  end

  begin
    app = proc {|env| [200, {"Content-Type" => "text/plain", "Content-Length" => "12"}, [Class.new(String).new("Hello World!")]] }
    response = Rack::MockRequest.new(Rack::Lint.new(app)).get('/')
  rescue Rack::Lint::LintError => e
    raise(e) unless e.message =~ /Body yielded non-string value/
    Rack::Lint.send :include, AllowStringSubclass
  end
end

Version data entries

31 entries across 31 versions & 8 rubygems

Version Path
actionpack-2.3.18 lib/action_controller/rack_lint_patch.rb
actionpack-2.3.17-rack-upgrade-2.3.17 lib/action_controller/rack_lint_patch.rb
actionpack-2.3.17 lib/action_controller/rack_lint_patch.rb
actionpack-2.3.16 lib/action_controller/rack_lint_patch.rb
actionpack-rack-upgrade-2-2.3.16 lib/action_controller/rack_lint_patch.rb
actionpack-rack-upgrade-2-2.3.15 lib/action_controller/rack_lint_patch.rb
actionpack-2.3.15 lib/action_controller/rack_lint_patch.rb
actionpack-rack-upgrade-2.3.16 lib/action_controller/rack_lint_patch.rb
actionpack-rack-upgrade-2.3.15 lib/action_controller/rack_lint_patch.rb
actionpack-rack-upgrade-2.3.14 lib/action_controller/rack_lint_patch.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/actionpack-2.3.14/lib/action_controller/rack_lint_patch.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/actionpack-2.3.12/lib/action_controller/rack_lint_patch.rb
actionpack-2.3.14 lib/action_controller/rack_lint_patch.rb
kajam-1.0.3.rc2 vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb
actionpack-2.3.12 lib/action_controller/rack_lint_patch.rb
radiant-1.0.0.rc2 vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb
radiant-1.0.0.rc1 vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb
actionpack-2.3.11 lib/action_controller/rack_lint_patch.rb
radiantcms-couchrest_model-0.1.4 vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb
radiantcms-couchrest_model-0.1.3 vendor/rails/actionpack/lib/action_controller/rack_lint_patch.rb