Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for frozen string literal compatibility. #1182

Merged
merged 1 commit into from Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rack/auth/digest/params.rb
Expand Up @@ -38,12 +38,12 @@ def []=(k, v)

def to_s
map do |k, v|
"#{k}=" << (UNQUOTED.include?(k) ? v.to_s : quote(v))
"#{k}=#{(UNQUOTED.include?(k) ? v.to_s : quote(v))}"
end.join(', ')
end

def quote(str) # From WEBrick::HTTPUtils
'"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
'"' + str.gsub(/[\\\"]/o, "\\\1") + '"'
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/multipart/parser.rb
Expand Up @@ -252,7 +252,7 @@ def handle_mime_head
filename = get_filename(head)

if name.nil? || name.empty?
name = filename || "#{content_type || TEXT_PLAIN}[]"
name = filename || "#{content_type || TEXT_PLAIN}[]".dup
end

@collector.on_mime_head @mime_index, head, filename, content_type, name
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/request.rb
Expand Up @@ -391,7 +391,7 @@ def delete_param(k)

def base_url
url = "#{scheme}://#{host}"
url << ":#{port}" if port != DEFAULT_PORTS[scheme]
url = "#{url}:#{port}" if port != DEFAULT_PORTS[scheme]
url
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rack/rewindable_input.rb
Expand Up @@ -72,7 +72,7 @@ def make_rewindable
@unlinked = true
end

buffer = ""
buffer = "".dup
while @io.read(1024 * 4, buffer)
entire_buffer_written_out = false
while !entire_buffer_written_out
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/show_exceptions.rb
Expand Up @@ -55,7 +55,7 @@ def accepts_html?(env)
private :accepts_html?

def dump_exception(exception)
string = "#{exception.class}: #{exception.message}\n"
string = "#{exception.class}: #{exception.message}\n".dup
string << exception.backtrace.map { |l| "\t#{l}" }.join("\n")
string
end
Expand Down
4 changes: 2 additions & 2 deletions test/spec_chunked.rb
Expand Up @@ -42,8 +42,8 @@ def chunked(app)
response.headers.wont_include 'Content-Length'
response.headers['Transfer-Encoding'].must_equal 'chunked'
response.body.encoding.to_s.must_equal "ASCII-8BIT"
response.body.must_equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n".force_encoding("BINARY")
response.body.must_equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n".force_encoding(Encoding::BINARY)
response.body.must_equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n".dup.force_encoding("BINARY")
response.body.must_equal "c\r\n\xFE\xFFH\x00e\x00l\x00l\x00o\x00\r\n2\r\n \x00\r\na\r\nW\x00o\x00r\x00l\x00d\x00\r\n0\r\n\r\n".dup.force_encoding(Encoding::BINARY)
end

it 'not modify response when Content-Length header present' do
Expand Down
2 changes: 1 addition & 1 deletion test/spec_deflater.rb
Expand Up @@ -57,7 +57,7 @@ def verify(expected_status, expected_body, accept_encoding, options = {}, &block

# verify body
unless options['skip_body_verify']
body_text = ''
body_text = ''.dup
body.each { |part| body_text << part }

deflated_body = case expected_encoding
Expand Down
4 changes: 2 additions & 2 deletions test/spec_directory.rb
Expand Up @@ -27,7 +27,7 @@ def setup

assert_equal 200, status

str = ''
str = ''.dup
body.each { |x| str << x }
assert_match "foo+bar", str
end
Expand Down Expand Up @@ -113,7 +113,7 @@ def setup

assert_equal 200, status

str = ''
str = ''.dup
body.each { |x| str << x }
assert_match "/foo%20bar/omg%20omg.txt", str
end
Expand Down
2 changes: 1 addition & 1 deletion test/spec_file.rb
Expand Up @@ -19,7 +19,7 @@ def file(*args)

assert_equal 200, status

str = ''
str = ''.dup
body.each { |x| str << x }
assert_match "hello world", str
end
Expand Down
6 changes: 3 additions & 3 deletions test/spec_lint.rb
Expand Up @@ -483,7 +483,7 @@ def rewind
end

def assert_lint(*args)
hello_str = "hello world"
hello_str = "hello world".dup
hello_str.force_encoding(Encoding::ASCII_8BIT)

Rack::Lint.new(lambda { |env|
Expand All @@ -498,8 +498,8 @@ def assert_lint(*args)
assert_lint 0
assert_lint 1
assert_lint nil
assert_lint nil, ''
assert_lint 1, ''
assert_lint nil, ''.dup
assert_lint 1, ''.dup
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/spec_multipart.rb
Expand Up @@ -201,7 +201,7 @@ def initialize(*)

it "parse multipart upload file using custom tempfile class" do
env = Rack::MockRequest.env_for("/", multipart_fixture(:text))
my_tempfile = ""
my_tempfile = "".dup
env['rack.multipart.tempfile_factory'] = lambda { |filename, content_type| my_tempfile }
params = Rack::Multipart.parse_multipart(env)
params["files"][:tempfile].object_id.must_equal my_tempfile.object_id
Expand Down Expand Up @@ -683,7 +683,7 @@ def initialize(*)
it "fallback to content-type for name" do
rack_logo = File.read(multipart_file("rack-logo.png"))

data = <<-EOF
data = <<-EOF.dup
--AaB03x\r
Content-Type: text/plain\r
\r
Expand All @@ -702,7 +702,7 @@ def initialize(*)
options = {
"CONTENT_TYPE" => "multipart/related; boundary=AaB03x",
"CONTENT_LENGTH" => data.bytesize.to_s,
:input => StringIO.new(data)
:input => StringIO.new(data.dup)
}
env = Rack::MockRequest.env_for("/", options)
params = Rack::Multipart.parse_multipart(env)
Expand Down
2 changes: 1 addition & 1 deletion test/spec_request.rb
Expand Up @@ -1106,7 +1106,7 @@ def initialize(*)
[200, {"Content-Type" => "text/html", "Content-Length" => size.to_s}, [content]]
}

input = <<EOF
input = <<EOF.dup
--AaB03x\r
content-disposition: form-data; name="reply"\r
\r
Expand Down
10 changes: 5 additions & 5 deletions test/spec_response.rb
Expand Up @@ -231,12 +231,12 @@
it "has a useful constructor" do
r = Rack::Response.new("foo")
status, header, body = r.finish
str = ""; body.each { |part| str << part }
str = "".dup; body.each { |part| str << part }
str.must_equal "foo"

r = Rack::Response.new(["foo", "bar"])
status, header, body = r.finish
str = ""; body.each { |part| str << part }
str = "".dup; body.each { |part| str << part }
str.must_equal "foobar"

object_with_each = Object.new
Expand All @@ -247,7 +247,7 @@ def object_with_each.each
r = Rack::Response.new(object_with_each)
r.write "foo"
status, header, body = r.finish
str = ""; body.each { |part| str << part }
str = "".dup; body.each { |part| str << part }
str.must_equal "foobarfoo"

r = Rack::Response.new([], 500)
Expand All @@ -263,15 +263,15 @@ def object_with_each.each
res.write "foo"
}
status, _, body = r.finish
str = ""; body.each { |part| str << part }
str = "".dup; body.each { |part| str << part }
str.must_equal "foo"
status.must_equal 404
end

it "doesn't return invalid responses" do
r = Rack::Response.new(["foo", "bar"], 204)
_, header, body = r.finish
str = ""; body.each { |part| str << part }
str = "".dup; body.each { |part| str << part }
str.must_be :empty?
header["Content-Type"].must_be_nil
header['Content-Length'].must_be_nil
Expand Down
10 changes: 5 additions & 5 deletions test/spec_rewindable_input.rb
Expand Up @@ -26,14 +26,14 @@ class << self # HACK to get this running w/ as few changes as possible
end

it "be able to handle to read(length, buffer)" do
buffer = ""
buffer = "".dup
result = @rio.read(1, buffer)
result.must_equal "h"
result.object_id.must_equal buffer.object_id
end

it "be able to handle to read(nil, buffer)" do
buffer = ""
buffer = "".dup
result = @rio.read(nil, buffer)
result.must_equal "hello world"
result.object_id.must_equal buffer.object_id
Expand Down Expand Up @@ -95,7 +95,7 @@ class << self # HACK to get this running w/ as few changes as possible
describe Rack::RewindableInput do
describe "given an IO object that is already rewindable" do
def setup
@io = StringIO.new("hello world")
@io = StringIO.new("hello world".dup)
super
end

Expand All @@ -104,7 +104,7 @@ def setup

describe "given an IO object that is not rewindable" do
def setup
@io = StringIO.new("hello world")
@io = StringIO.new("hello world".dup)
@io.instance_eval do
undef :rewind
end
Expand All @@ -116,7 +116,7 @@ def setup

describe "given an IO object whose rewind method raises Errno::ESPIPE" do
def setup
@io = StringIO.new("hello world")
@io = StringIO.new("hello world".dup)
def @io.rewind
raise Errno::ESPIPE, "You can't rewind this!"
end
Expand Down
2 changes: 1 addition & 1 deletion test/spec_session_cookie.rb
Expand Up @@ -423,7 +423,7 @@ def call(env)
@counter = 0
app = lambda do |env|
env["rack.session"]["message"] ||= ""
env["rack.session"]["message"] << "#{(@counter += 1).to_s}--"
env["rack.session"]["message"] += "#{(@counter += 1).to_s}--"
hash = env["rack.session"].dup
hash.delete("session_id")
Rack::Response.new(hash["message"]).to_a
Expand Down