Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rack.input should be ASCII-8BIT even if it's StringIO (for test)

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit f23e8330085e6967b9e57a26b293bd08fa4b0d53 1 parent ce26ede
@takahashim takahashim authored josh committed
View
4 lib/rack/mock.rb
@@ -114,7 +114,9 @@ def self.env_for(uri="", opts={})
end
end
- opts[:input] ||= ""
+ empty_str = ""
+ empty_str.force_encoding("ASCII-8BIT") if empty_str.respond_to? :force_encoding
+ opts[:input] ||= empty_str
if String === opts[:input]
rack_input = StringIO.new(opts[:input])
else
View
14 test/spec_rack_lint.rb
@@ -454,46 +454,48 @@ def rewind
end
specify "passes valid read calls" do
+ hello_str = "hello world"
+ hello_str.force_encoding("ASCII-8BIT") if hello_str.respond_to? :force_encoding
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read(0)
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read(1)
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read(nil)
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read(nil, '')
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
lambda {
Rack::Lint.new(lambda { |env|
env["rack.input"].read(1, '')
[201, {"Content-type" => "text/plain", "Content-length" => "0"}, []]
- }).call(env({"rack.input" => StringIO.new("hello world")}))
+ }).call(env({"rack.input" => StringIO.new(hello_str)}))
}.should.not.raise(Rack::Lint::LintError)
end
end
View
1  test/spec_rack_request.rb
@@ -429,6 +429,7 @@
/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg\r
--AaB03x--\r
EOF
+ input.force_encoding("ASCII-8BIT") if input.respond_to? :force_encoding
res = Rack::MockRequest.new(Rack::Lint.new(app)).get "/",
"CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
"CONTENT_LENGTH" => input.size.to_s, "rack.input" => StringIO.new(input)
Please sign in to comment.
Something went wrong with that request. Please try again.