9ece6666bf
4-byte utf8 chars like emoji are passed around in ruby fine, but when they are put into mysql queries, strings get truncated at the first mb4 character. to prevent truncation, strip out mb4 characters in most user-controlled fields like comments, story descriptions and titles, and messages. to properly support utf8mb4, mysql server 5.5 is needed, the table encodings need to be changed to utf8mb4, and the mysql2 gem needs to be upgraded once it supports utf8mb4: https://github.com/brianmario/mysql2/issues/249
31 lines
589 B
Ruby
31 lines
589 B
Ruby
module ActiveRecord
|
|
class Base
|
|
def self.q(str)
|
|
ActiveRecord::Base.connection.quote(str)
|
|
end
|
|
|
|
def q(str)
|
|
ActiveRecord::Base.connection.quote(str)
|
|
end
|
|
end
|
|
end
|
|
|
|
# XXX stupid hack to strip out utf8mb4 chars that may break mysql queries
|
|
# TODO upgrade to mysql 5.5, convert tables to utf8mb4, upgrade mysql2 gem when
|
|
# it supports utf8mb4, and remove this hack
|
|
class String
|
|
def remove_mb4
|
|
t = "".force_encoding(self.encoding)
|
|
|
|
self.each_char do |c|
|
|
if c.bytesize == 4
|
|
t << " "
|
|
else
|
|
t << c
|
|
end
|
|
end
|
|
|
|
t
|
|
end
|
|
end
|