mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use Encoding::UTF_8 constant 🚯
This commit is contained in:
parent
59deaecc76
commit
5f30b547c8
10 changed files with 15 additions and 15 deletions
|
@ -55,7 +55,7 @@ module ActionDispatch
|
|||
# should really prevent that from happening
|
||||
def encode_params(params)
|
||||
if params.is_a?(String)
|
||||
return params.force_encoding("UTF-8").encode!
|
||||
return params.force_encoding(Encoding::UTF_8).encode!
|
||||
elsif !params.is_a?(Hash)
|
||||
return params
|
||||
end
|
||||
|
|
|
@ -70,7 +70,7 @@ module ActionDispatch
|
|||
|
||||
def encode_filename(filename)
|
||||
# Encode the filename in the utf8 encoding, unless it is nil
|
||||
filename.force_encoding("UTF-8").encode! if filename
|
||||
filename.force_encoding(Encoding::UTF_8).encode! if filename
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ module ActionDispatch
|
|||
|
||||
def generate_sid
|
||||
sid = SecureRandom.hex(16)
|
||||
sid.encode!('UTF-8')
|
||||
sid.encode!(Encoding::UTF_8)
|
||||
sid
|
||||
end
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ module ActionView
|
|||
"'" => "\\'"
|
||||
}
|
||||
|
||||
JS_ESCAPE_MAP["\342\200\250".force_encoding('UTF-8').encode!] = '
'
|
||||
JS_ESCAPE_MAP["\342\200\251".force_encoding('UTF-8').encode!] = '
'
|
||||
JS_ESCAPE_MAP["\342\200\250".force_encoding(Encoding::UTF_8).encode!] = '
'
|
||||
JS_ESCAPE_MAP["\342\200\251".force_encoding(Encoding::UTF_8).encode!] = '
'
|
||||
|
||||
# Escapes carriage returns and single and double quotes for JavaScript segments.
|
||||
#
|
||||
|
|
|
@ -35,7 +35,7 @@ class ResponseTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
def test_response_body_encoding
|
||||
body = ["hello".encode('utf-8')]
|
||||
body = ["hello".encode(Encoding::UTF_8)]
|
||||
response = ActionDispatch::Response.new 200, {}, body
|
||||
assert_equal Encoding::UTF_8, response.body.encoding
|
||||
end
|
||||
|
|
|
@ -27,8 +27,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('UTF-8').encode!)
|
||||
assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\251 newline).force_encoding('UTF-8').encode!)
|
||||
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 %(dont <\\/close> tags), j(%(dont </close> tags))
|
||||
end
|
||||
|
|
|
@ -95,8 +95,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('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('UTF-8'), :length => 10)
|
||||
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)
|
||||
end
|
||||
|
||||
def test_truncate_does_not_modify_the_options_hash
|
||||
|
@ -293,7 +293,7 @@ class TextHelperTest < ActionView::TestCase
|
|||
end
|
||||
|
||||
def test_excerpt_with_utf8
|
||||
assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', :radius => 8))
|
||||
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))
|
||||
end
|
||||
|
||||
def test_excerpt_does_not_modify_the_options_hash
|
||||
|
|
|
@ -17,7 +17,7 @@ module ActiveRecord
|
|||
@conn.extend(Module.new { def logger; end })
|
||||
column = Struct.new(:type, :name).new(:string, "foo")
|
||||
binary = SecureRandom.hex
|
||||
expected = binary.dup.encode!('utf-8')
|
||||
expected = binary.dup.encode!(Encoding::UTF_8)
|
||||
assert_equal expected, @conn.type_cast(binary, column)
|
||||
end
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ unless current_adapter?(:SybaseAdapter, :DB2Adapter, :FirebirdAdapter)
|
|||
|
||||
# Mysql adapter doesn't properly encode things, so we have to do it
|
||||
if current_adapter?(:MysqlAdapter)
|
||||
name.force_encoding('UTF-8')
|
||||
name.force_encoding(Encoding::UTF_8)
|
||||
end
|
||||
assert_equal 'いただきます!', name
|
||||
end
|
||||
|
|
|
@ -269,8 +269,8 @@ class StringInflectionsTest < ActiveSupport::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('UTF-8'),
|
||||
"\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('UTF-8').truncate(10)
|
||||
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8),
|
||||
"\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).truncate(10)
|
||||
end
|
||||
|
||||
def test_truncate_should_not_be_html_safe
|
||||
|
|
Loading…
Reference in a new issue