File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
activerecord/lib/active_record/connection_adapters Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,10 @@ def quote(value)
16
16
when false then quoted_false
17
17
when nil then "NULL"
18
18
# BigDecimals need to be put in a non-normalized form and quoted.
19
- when BigDecimal then value . to_s ( "F" )
19
+ # Additionally, for Ruby 2.7, the string returned by `to_s` is ASCII-8BIT.
20
+ # We want to avoid that, as that will cause the string to be quoted as
21
+ # binary. It is safe to force the encoding to US-ASCII.
22
+ when BigDecimal then value . to_s ( "F" ) . force_encoding ( Encoding ::US_ASCII )
20
23
when Numeric then value . to_s
21
24
when Type ::Binary ::Data then quoted_binary ( value )
22
25
when Type ::Time ::Value then "'#{ quoted_time ( value ) } '"
Original file line number Diff line number Diff line change @@ -23,10 +23,13 @@ def cast_bound_value(value)
23
23
case value
24
24
when Rational
25
25
value . to_f . to_s
26
+ when BigDecimal
27
+ # For Ruby 2.7, the string returned by `to_s` is ASCII-8BIT.
28
+ # We want to avoid that, as that will cause the string to be quoted as
29
+ # binary. It is safe to force the encoding to US-ASCII.
30
+ value . to_s ( "F" ) . force_encoding ( Encoding ::US_ASCII )
26
31
when Numeric
27
32
value . to_s
28
- when BigDecimal
29
- value . to_s ( "F" )
30
33
when true
31
34
"1"
32
35
when false
You can’t perform that action at this time.
0 commit comments