diff options
author | Masayoshi Takahashi <takahashimm@gmail.com> | 2009-08-03 11:41:05 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-08-03 11:41:05 -0500 |
commit | f23e8330085e6967b9e57a26b293bd08fa4b0d53 (patch) | |
tree | a98551fa5f71c1222696e72e06f84e21a8f8804b | |
parent | ce26ede59d9e833ee233edff8d9ec73c6ecb0998 (diff) | |
download | rack-f23e8330085e6967b9e57a26b293bd08fa4b0d53.tar.gz |
rack.input should be ASCII-8BIT even if it's StringIO (for test)
Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r-- | lib/rack/mock.rb | 4 | ||||
-rw-r--r-- | test/spec_rack_lint.rb | 14 | ||||
-rw-r--r-- | test/spec_rack_request.rb | 1 |
3 files changed, 12 insertions, 7 deletions
diff --git a/lib/rack/mock.rb b/lib/rack/mock.rb index 4b85ea12..7964c447 100644 --- a/lib/rack/mock.rb +++ b/lib/rack/mock.rb @@ -114,7 +114,9 @@ module Rack 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 diff --git a/test/spec_rack_lint.rb b/test/spec_rack_lint.rb index a227b56d..30492ad8 100644 --- a/test/spec_rack_lint.rb +++ b/test/spec_rack_lint.rb @@ -454,46 +454,48 @@ context "Rack::Lint" do 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 diff --git a/test/spec_rack_request.rb b/test/spec_rack_request.rb index facbe753..fe000c24 100644 --- a/test/spec_rack_request.rb +++ b/test/spec_rack_request.rb @@ -429,6 +429,7 @@ Content-Transfer-Encoding: base64\r /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) |