1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make ActiveModel frozen string literal friendly.

Includes two external changes because they're referenced within the ActiveModel test suite.
This commit is contained in:
Pat Allan 2017-06-20 18:35:44 +10:00
parent 036bdee4d5
commit 4ff30d9bb6
4 changed files with 5 additions and 5 deletions

View file

@ -29,7 +29,7 @@ module ActionDispatch
ENCODE = "%%%02X".freeze
US_ASCII = Encoding::US_ASCII
UTF_8 = Encoding::UTF_8
EMPTY = "".force_encoding(US_ASCII).freeze
EMPTY = "".dup.force_encoding(US_ASCII).freeze
DEC2HEX = (0..255).to_a.map { |i| ENCODE % i }.map { |s| s.force_encoding(US_ASCII) }
ALPHA = "a-zA-Z".freeze

View file

@ -13,8 +13,8 @@ module ActionView
"'" => "\\'"
}
JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = "
"
JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = "
"
JS_ESCAPE_MAP["\342\200\250".dup.force_encoding(Encoding::UTF_8).encode!] = "
"
JS_ESCAPE_MAP["\342\200\251".dup.force_encoding(Encoding::UTF_8).encode!] = "
"
# Escapes carriage returns and single and double quotes for JavaScript segments.
#

View file

@ -96,7 +96,7 @@ class DirtyTest < ActiveModel::TestCase
end
test "attribute mutation" do
@model.instance_variable_set("@name", "Yam")
@model.instance_variable_set("@name", "Yam".dup)
assert !@model.name_changed?
@model.name.replace("Hadad")
assert !@model.name_changed?

View file

@ -14,7 +14,7 @@ module ActiveModel
test "cast strings are mutable" do
type = Type::String.new
s = "foo"
s = "foo".dup
assert_equal false, type.cast(s).frozen?
assert_equal false, s.frozen?