Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions bin/passenger-install-nginx-module
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,7 @@ private
# We do this instead of using #file, for Ruby 1.8.5 support.
digest = Digest::SHA256.new
File.open(path, "rb") do |f|
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
buf = String.new(encoding: Encoding::BINARY)
else
buf = ""
buf.force_encoding('binary') if buf.respond_to?(:force_encoding)
end
buf = ''.b
while !f.eof?
f.read(1024 * 16, buf)
digest.update(buf)
Expand Down
7 changes: 1 addition & 6 deletions dev/ruby_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,7 @@ def start_thread
def handle_next_client(forward_connection)
client = @server.accept
begin
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
buffer = String.new(encoding: Encoding::BINARY)
else
buffer = ""
buffer.force_encoding('binary') if buffer.respond_to?(:force_encoding)
end
buffer = "".b
while true
begin
read_header(client, buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def list_processes(options)
ps_output = `#{ps} -w -o pid,ppid,nlwp,vsz,rss,%cpu,command`
threads_known = true
end
list = force_binary(ps_output).split("\n")
list = ps_output.b.split("\n")
list.shift
list.each do |line|
line.gsub!(/^ */, '')
Expand Down Expand Up @@ -297,16 +297,6 @@ def determine_private_dirty_rss(pid)
rescue Errno::EACCES, Errno::ENOENT, Errno::ESRCH
return nil
end

if ''.respond_to?(:force_encoding)
def force_binary(str)
str.force_encoding('binary')
end
else
def force_binary(str)
str
end
end
end

end # module AdminTools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ def install
def main_loop(finish_callback)
socket_wrapper = Utils::UnseekableSocket.new
channel = MessageChannel.new
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
buffer = String.new(encoding: Encoding::BINARY)
else
buffer = ""
buffer.force_encoding('binary') if buffer.respond_to?(:force_encoding)
end
buffer = ''.b

begin
finish_callback.call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,8 @@ def default_group_for(username)
end

def serialize_strset(*items)
if "".respond_to?(:force_encoding)
items = items.map { |x| x.force_encoding('binary') }
null = "\0".force_encoding('binary')
else
null = "\0"
end
items = items.map(&:b)
null = "\0".b
return [items.join(null)].pack('m*').gsub("\n", "").strip
end

Expand Down
14 changes: 2 additions & 12 deletions src/ruby_supportlib/phusion_passenger/utils/unseekable_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def gets
if @simulate_eof
length, buffer = args
if buffer
buffer.replace(binary_string(""))
buffer.replace("".b)
else
buffer = binary_string("")
buffer = "".b
end
if length
return nil
Expand Down Expand Up @@ -292,16 +292,6 @@ def annotate(exception)
def raise_error_because_activity_disallowed!
raise IOError, "It is not possible to read or write from the client socket because the current."
end

if ''.respond_to?(:force_encoding)
def binary_string(str)
return ''.force_encoding('binary')
end
else
def binary_string(str)
return ''
end
end
end

end # module Utils
Expand Down
5 changes: 2 additions & 3 deletions test/integration_tests/native_packaging_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ module PhusionPassenger
describe "A natively packaged Phusion Passenger" do
def capture_output(command)
output = `#{command}`.strip
if output.respond_to?(:force_encoding)
output.force_encoding('utf-8')
end
output.force_encoding(Encoding::UTF_8)

if $?.exitstatus == 0
return output
else
Expand Down
6 changes: 3 additions & 3 deletions test/integration_tests/shared/example_webapp_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
io.read
end
response.should ==
binary_string("name 1 = Kotonoha\n") <<
binary_string("name 2 = Sekai\n") <<
binary_string("data = ") << static_file.read
"name 1 = Kotonoha\n".b <<
"name 2 = Sekai\n".b <<
"data = ".b << static_file.read
ensure
static_file.close
end
Expand Down
5 changes: 2 additions & 3 deletions test/integration_tests/standalone_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def sh(*command)

def capture_output(command)
output = `#{command} 2>&1`.strip
if output.respond_to?(:force_encoding)
output.force_encoding('utf-8')
end
output.force_encoding(Encoding::UTF_8)

if $?.exitstatus == 0
output
else
Expand Down
4 changes: 2 additions & 2 deletions test/stub/rack/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ app = lambda do |env|
text_response("This is the uncached version of /cached")
when '/upload_with_params'
req = Rack::Request.new(env)
name1 = binary_string(req.params["name1"])
name2 = binary_string(req.params["name2"])
name1 = req.params["name1"].b
name2 = req.params["name2"].b
file = req.params["data"][:tempfile]
file.binmode
text_response(
Expand Down
12 changes: 1 addition & 11 deletions test/stub/rack/library.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# encoding: binary

def text_response(body)
body = binary_string(body.to_s)
body = body.to_s.b
return [200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]]
end

if "".respond_to?(:force_encoding)
def binary_string(str)
return str.force_encoding("binary")
end
else
def binary_string(str)
return str
end
end
10 changes: 0 additions & 10 deletions test/support/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,6 @@ def inspect_server(name)
return instance
end
end

if "".respond_to?(:force_encoding)
def binary_string(str)
return str.force_encoding("binary")
end
else
def binary_string(str)
return str
end
end
end

File.class_eval do
Expand Down