mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make ActionView frozen string literal friendly.
Plus a couple of related ActionPack patches.
This commit is contained in:
parent
dd491b24ff
commit
3d453b409d
22 changed files with 223 additions and 223 deletions
|
@ -24,7 +24,7 @@ module ActionController
|
|||
exception_class_name = payload[:exception].first
|
||||
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
||||
end
|
||||
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
|
||||
message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms".dup
|
||||
message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
|
||||
message << "\n\n" if defined?(Rails.env) && Rails.env.development?
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ module ActionDispatch
|
|||
path.squeeze!("/".freeze)
|
||||
path.sub!(%r{/+\Z}, "".freeze)
|
||||
path.gsub!(/(%[a-f0-9]{2})/) { $1.upcase }
|
||||
path = "/" if path == "".freeze
|
||||
path = "/".dup if path == "".freeze
|
||||
path.force_encoding(encoding)
|
||||
path
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ module ActionDispatch
|
|||
def generate_response_message(expected, actual = @response.response_code)
|
||||
"Expected response to be a <#{code_with_name(expected)}>,"\
|
||||
" but was a <#{code_with_name(actual)}>"
|
||||
.concat(location_if_redirected).concat(response_body_if_short)
|
||||
.dup.concat(location_if_redirected).concat(response_body_if_short)
|
||||
end
|
||||
|
||||
def response_body_if_short
|
||||
|
|
|
@ -1007,7 +1007,7 @@ module ActionView
|
|||
select_options[:disabled] = "disabled" if @options[:disabled]
|
||||
select_options[:class] = css_class_attribute(type, select_options[:class], @options[:with_css_classes]) if @options[:with_css_classes]
|
||||
|
||||
select_html = "\n"
|
||||
select_html = "\n".dup
|
||||
select_html << content_tag("option".freeze, "", value: "") + "\n" if @options[:include_blank]
|
||||
select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt]
|
||||
select_html << select_options_as_html
|
||||
|
@ -1089,7 +1089,7 @@ module ActionView
|
|||
# Given an ordering of datetime components, create the selection HTML
|
||||
# and join them with their appropriate separators.
|
||||
def build_selects_from_types(order)
|
||||
select = ""
|
||||
select = "".dup
|
||||
first_visible = order.find { |type| !@options[:"discard_#{type}"] }
|
||||
order.reverse_each do |type|
|
||||
separator = separator(type) unless type == first_visible # don't add before first visible field
|
||||
|
|
|
@ -95,7 +95,7 @@ module ActionView
|
|||
raise e if raise_error
|
||||
|
||||
keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
|
||||
title = "translation missing: #{keys.join('.')}"
|
||||
title = "translation missing: #{keys.join('.')}".dup
|
||||
|
||||
interpolations = options.except(:default, :scope)
|
||||
if interpolations.any?
|
||||
|
|
|
@ -14,7 +14,7 @@ module ActionView
|
|||
|
||||
def render_template(event)
|
||||
info do
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}"
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup
|
||||
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
||||
message << " (#{event.duration.round(1)}ms)"
|
||||
end
|
||||
|
@ -22,7 +22,7 @@ module ActionView
|
|||
|
||||
def render_partial(event)
|
||||
info do
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}"
|
||||
message = " Rendered #{from_rails_root(event.payload[:identifier])}".dup
|
||||
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
||||
message << " (#{event.duration.round(1)}ms)"
|
||||
message << " #{cache_message(event.payload)}" unless event.payload[:cache_hit].nil?
|
||||
|
|
|
@ -329,7 +329,7 @@ module ActionView
|
|||
locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
|
||||
|
||||
# Double assign to suppress the dreaded 'assigned but unused variable' warning
|
||||
locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
|
||||
locals.each_with_object("".dup) { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" }
|
||||
end
|
||||
|
||||
def method_name
|
||||
|
|
|
@ -104,7 +104,7 @@ module ActionView
|
|||
# empty string ensures buffer has UTF-8 encoding as
|
||||
# new without arguments returns ASCII-8BIT encoded buffer like String#new
|
||||
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
||||
@rendered = ""
|
||||
@rendered = "".dup
|
||||
|
||||
make_test_case_available_to_view!
|
||||
say_no_to_protect_against_forgery!
|
||||
|
|
|
@ -20,7 +20,7 @@ module ActionView #:nodoc:
|
|||
private
|
||||
|
||||
def query(path, exts, _, _)
|
||||
query = ""
|
||||
query = "".dup
|
||||
EXTENSIONS.each_key do |ext|
|
||||
query << "(" << exts[ext].map { |e| e && Regexp.escape(".#{e}") }.join("|") << "|)"
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ class FormHelperActiveRecordTest < ActionView::TestCase
|
|||
private
|
||||
|
||||
def hidden_fields(method = nil)
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
txt << %{<input name="_method" type="hidden" value="#{method}" />}
|
||||
|
@ -65,7 +65,7 @@ class FormHelperActiveRecordTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
|
2
actionview/test/fixtures/ruby_template.ruby
vendored
2
actionview/test/fixtures/ruby_template.ruby
vendored
|
@ -1,2 +1,2 @@
|
|||
body = ""
|
||||
body = "".dup
|
||||
body << ["Hello", "from", "Ruby", "code"].join(" ")
|
||||
|
|
|
@ -194,7 +194,7 @@ class ScrollsController < ActionController::Base
|
|||
FEEDS["provide_builder"] = <<-'EOT'
|
||||
# we pass in the new_xml to the helper so it doesn't
|
||||
# call anything on the original builder
|
||||
new_xml = Builder::XmlMarkup.new(:target=>'')
|
||||
new_xml = Builder::XmlMarkup.new(:target=>''.dup)
|
||||
atom_feed(:xml => new_xml) do |feed|
|
||||
feed.title("My great blog!")
|
||||
feed.updated(@scrolls.first.created_at)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -16,7 +16,7 @@ class FormWithActsLikeFormTagTest < FormWithTest
|
|||
method = options[:method]
|
||||
skip_enforcing_utf8 = options.fetch(:skip_enforcing_utf8, false)
|
||||
|
||||
"".tap do |txt|
|
||||
"".dup.tap do |txt|
|
||||
unless skip_enforcing_utf8
|
||||
txt << %{<input name="utf8" type="hidden" value="✓" />}
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ class FormWithActsLikeFormTagTest < FormWithTest
|
|||
|
||||
method = method.to_s == "get" ? "get" : "post"
|
||||
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt << %{ enctype="multipart/form-data"} if enctype
|
||||
txt << %{ data-remote="true"} unless local
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
@ -2194,9 +2194,9 @@ class FormWithActsLikeFormForTest < FormWithTest
|
|||
method = options[:method]
|
||||
|
||||
if options.fetch(:skip_enforcing_utf8, false)
|
||||
txt = ""
|
||||
txt = "".dup
|
||||
else
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
end
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
|
@ -2207,7 +2207,7 @@ class FormWithActsLikeFormForTest < FormWithTest
|
|||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, local = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} unless local
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
|
|
@ -3446,9 +3446,9 @@ class FormHelperTest < ActionView::TestCase
|
|||
method = options[:method]
|
||||
|
||||
if options.fetch(:enforce_utf8, true)
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}
|
||||
txt = %{<input name="utf8" type="hidden" value="✓" />}.dup
|
||||
else
|
||||
txt = ""
|
||||
txt = "".dup
|
||||
end
|
||||
|
||||
if method && !%w(get post).include?(method.to_s)
|
||||
|
@ -3459,7 +3459,7 @@ class FormHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt << %{ enctype="multipart/form-data"} if multipart
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
|
|
@ -14,7 +14,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
method = options[:method]
|
||||
enforce_utf8 = options.fetch(:enforce_utf8, true)
|
||||
|
||||
"".tap do |txt|
|
||||
"".dup.tap do |txt|
|
||||
if enforce_utf8
|
||||
txt << %{<input name="utf8" type="hidden" value="✓" />}
|
||||
end
|
||||
|
@ -30,7 +30,7 @@ class FormTagHelperTest < ActionView::TestCase
|
|||
|
||||
method = method.to_s == "get" ? "get" : "post"
|
||||
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}
|
||||
txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup
|
||||
txt << %{ enctype="multipart/form-data"} if enctype
|
||||
txt << %{ data-remote="true"} if remote
|
||||
txt << %{ class="#{html_class}"} if html_class
|
||||
|
|
|
@ -20,8 +20,8 @@ class JavaScriptHelperTest < ActionView::TestCase
|
|||
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
||||
assert_equal %(backslash\\\\test), escape_javascript(%(backslash\\test))
|
||||
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\251 newline).force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).dup.force_encoding(Encoding::UTF_8).encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\251 newline).dup.force_encoding(Encoding::UTF_8).encode!)
|
||||
|
||||
assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
|
||||
end
|
||||
|
|
|
@ -439,7 +439,7 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
CustomHandler = lambda do |template|
|
||||
"@output_buffer = ''\n" \
|
||||
"@output_buffer = ''.dup\n" \
|
||||
"@output_buffer << 'source: #{template.source.inspect}'\n"
|
||||
end
|
||||
|
||||
|
@ -583,7 +583,7 @@ module RenderTestCases
|
|||
|
||||
def test_render_with_passing_couple_extensions_to_one_register_template_handler_function_call
|
||||
ActionView::Template.register_template_handler :foo1, :foo2, CustomHandler
|
||||
assert_equal @view.render(inline: "Hello, World!", type: :foo1), @view.render(inline: "Hello, World!", type: :foo2)
|
||||
assert_equal @view.render(inline: "Hello, World!".dup, type: :foo1), @view.render(inline: "Hello, World!".dup, type: :foo2)
|
||||
ensure
|
||||
ActionView::Template.unregister_template_handler :foo1, :foo2
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ class FiberedTest < ActiveSupport::TestCase
|
|||
|
||||
def buffered_render(options)
|
||||
body = render_body(options)
|
||||
string = ""
|
||||
string = "".dup
|
||||
body.each do |piece|
|
||||
string << piece
|
||||
end
|
||||
|
|
|
@ -53,7 +53,7 @@ class TestERBTemplate < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def new_template(body = "<%= hello %>", details = { format: :html })
|
||||
ActionView::Template.new(body, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details))
|
||||
ActionView::Template.new(body.dup, "hello template", details.fetch(:handler) { ERBHandler }, { virtual_path: "hello" }.merge!(details))
|
||||
end
|
||||
|
||||
def render(locals = {})
|
||||
|
|
|
@ -11,7 +11,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_concat
|
||||
self.output_buffer = "foo"
|
||||
self.output_buffer = "foo".dup
|
||||
assert_equal "foobar", concat("bar")
|
||||
assert_equal "foobar", output_buffer
|
||||
end
|
||||
|
@ -104,8 +104,8 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_truncate_multibyte
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8),
|
||||
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8), length: 10)
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".dup.force_encoding(Encoding::UTF_8),
|
||||
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".dup.force_encoding(Encoding::UTF_8), length: 10)
|
||||
end
|
||||
|
||||
def test_truncate_does_not_modify_the_options_hash
|
||||
|
@ -325,7 +325,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_excerpt_with_utf8
|
||||
assert_equal("...\357\254\203ciency could not be...".force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding(Encoding::UTF_8), "could", radius: 8))
|
||||
assert_equal("...\357\254\203ciency could not be...".dup.force_encoding(Encoding::UTF_8), excerpt("That's why e\357\254\203ciency could not be helped".dup.force_encoding(Encoding::UTF_8), "could", radius: 8))
|
||||
end
|
||||
|
||||
def test_excerpt_does_not_modify_the_options_hash
|
||||
|
|
|
@ -535,7 +535,7 @@ class UrlHelperTest < ActiveSupport::TestCase
|
|||
|
||||
def test_current_page_with_escaped_params_with_different_encoding
|
||||
@request = request_for_url("/")
|
||||
@request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do
|
||||
@request.stub(:path, "/category/administra%c3%a7%c3%a3o".dup.force_encoding(Encoding::ASCII_8BIT)) do
|
||||
assert current_page?(controller: "foo", action: "category", category: "administração")
|
||||
assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue