Skip to content

Commit 5e9d619

Browse files
committed
Avoid triggering AS::Multibyte deprecation when quoting
Followup: rails#54081
1 parent aaa111f commit 5e9d619

File tree

1 file changed

+14
-5
lines changed
  • activerecord/lib/active_record/connection_adapters/abstract

1 file changed

+14
-5
lines changed

activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require "active_support/core_ext/big_decimal/conversions"
4-
require "active_support/multibyte/chars"
54

65
module ActiveRecord
76
module ConnectionAdapters # :nodoc:
@@ -72,7 +71,7 @@ def quote_table_name(table_name)
7271
# {SQL injection attacks}[https://en.wikipedia.org/wiki/SQL_injection].
7372
def quote(value)
7473
case value
75-
when String, Symbol, ActiveSupport::Multibyte::Chars
74+
when String, Symbol
7675
"'#{quote_string(value.to_s)}'"
7776
when true then quoted_true
7877
when false then quoted_false
@@ -84,7 +83,12 @@ def quote(value)
8483
when Type::Time::Value then "'#{quoted_time(value)}'"
8584
when Date, Time then "'#{quoted_date(value)}'"
8685
when Class then "'#{value}'"
87-
else raise TypeError, "can't quote #{value.class.name}"
86+
else
87+
if value.class.name == "ActiveSupport::Multibyte::Chars"
88+
"'#{quote_string(value.to_s)}'"
89+
else
90+
raise TypeError, "can't quote #{value.class.name}"
91+
end
8892
end
8993
end
9094

@@ -93,7 +97,7 @@ def quote(value)
9397
# to a String.
9498
def type_cast(value)
9599
case value
96-
when Symbol, ActiveSupport::Multibyte::Chars, Type::Binary::Data
100+
when Symbol, Type::Binary::Data
97101
value.to_s
98102
when true then unquoted_true
99103
when false then unquoted_false
@@ -102,7 +106,12 @@ def type_cast(value)
102106
when nil, Numeric, String then value
103107
when Type::Time::Value then quoted_time(value)
104108
when Date, Time then quoted_date(value)
105-
else raise TypeError, "can't cast #{value.class.name}"
109+
else
110+
if value.class.name == "ActiveSupport::Multibyte::Chars"
111+
value.to_s
112+
else
113+
raise TypeError, "can't cast #{value.class.name}"
114+
end
106115
end
107116
end
108117

0 commit comments

Comments
 (0)