Skip to content

Commit

Permalink
Make actionpack frozen string friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Jul 24, 2017
1 parent 9c35bf2 commit c0e2cfd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "base64"
require "active_support/security_utils"

Expand Down Expand Up @@ -475,7 +477,7 @@ def params_array_from(raw_params)

# This removes the <tt>"</tt> characters wrapping the value.
def rewrite_param_values(array_params)
array_params.each { |param| (param[1] || "").gsub! %r/^"|"$/, "" }
array_params.each { |param| (param[1] || "".dup).gsub! %r/^"|"$/, "" }
end

# This method takes an authorization body and splits up the key-value
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def raw_post
# variable is already set, wrap it in a StringIO.
def body
if raw_post = get_header("RAW_POST_DATA")
raw_post.force_encoding(Encoding::BINARY)
raw_post = raw_post.dup.force_encoding(Encoding::BINARY)
StringIO.new(raw_post)
else
body_stream
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/abstract/callbacks_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

module AbstractController
Expand Down Expand Up @@ -42,7 +44,7 @@ def second
def aroundz
@aroundz = "FIRST"
yield
@aroundz << "SECOND"
@aroundz += "SECOND"
end

def index
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/controller/filters_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

class ActionController::Base
Expand Down Expand Up @@ -346,7 +348,7 @@ def self.before(controller)
class AroundFilter
def before(controller)
@execution_log = "before"
controller.class.execution_log << " before aroundfilter " if controller.respond_to? :execution_log
controller.class.execution_log += " before aroundfilter " if controller.respond_to? :execution_log
controller.instance_variable_set(:"@before_ran", true)
end

Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/controller/helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

ActionController::Base.helpers_path = File.expand_path("../fixtures/helpers", __dir__)
Expand Down Expand Up @@ -106,7 +108,7 @@ def delegate_method() end

def setup
# Increment symbol counter.
@symbol = (@@counter ||= "A0").succ!.dup
@symbol = (@@counter ||= "A0").succ.dup

# Generate new controller class.
controller_class_name = "Helper#{@symbol}Controller"
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/controller/http_token_authentication_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

class HttpTokenAuthenticationTest < ActionController::TestCase
Expand Down Expand Up @@ -148,7 +150,7 @@ def authenticate_long_credentials
end

test "token_and_options returns empty string with empty token" do
token = ""
token = "".dup
actual = ActionController::HttpAuthentication::Token.token_and_options(sample_request(token)).first
expected = token
assert_equal(expected, actual)
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/controller/new_base/bare_metal_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

module BareMetalTest
Expand All @@ -11,7 +13,7 @@ class BareTest < ActiveSupport::TestCase
test "response body is a Rack-compatible response" do
status, headers, body = BareController.action(:index).call(Rack::MockRequest.env_for("/"))
assert_equal 200, status
string = ""
string = "".dup

body.each do |part|
assert part.is_a?(String), "Each part of the body must be a String"
Expand Down
4 changes: 3 additions & 1 deletion actionpack/test/controller/new_base/middleware_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"

module MiddlewareTest
Expand All @@ -21,7 +23,7 @@ def initialize(app)

def call(env)
result = @app.call(env)
result[1]["Middleware-Order"] << "!"
result[1]["Middleware-Order"] += "!"
result
end
end
Expand Down
6 changes: 4 additions & 2 deletions actionpack/test/controller/webservice_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "abstract_unit"
require "active_support/json/decoding"

Expand All @@ -21,8 +23,8 @@ def dump_params_keys(hash = params)
value = ""
end

s << ", " unless s.empty?
s << "#{k}#{value}"
s += ", " unless s.empty?
s += "#{k}#{value}"
end
end
end
Expand Down

0 comments on commit c0e2cfd

Please sign in to comment.