mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 09:22:42 +08:00
DEV: Clean up freedom patches
This patch removes some of our freedom patches that have been deprecated for some time now. Some of them have been updated so we’re not shipping code based on an old version of Rails.
This commit is contained in:

committed by
Loïc Guitaut

parent
bf3260faea
commit
357011eb3b
@ -5,42 +5,32 @@
|
||||
#
|
||||
# The alternative is a broken website when this happens
|
||||
|
||||
class ActiveSupport::SafeBuffer
|
||||
def concat(value, raise_encoding_err = false)
|
||||
if !html_safe? || value.html_safe?
|
||||
module FreedomPatches
|
||||
module SafeBuffer
|
||||
def concat(value, raise_encoding_err = false)
|
||||
super(value)
|
||||
else
|
||||
super(ERB::Util.h(value))
|
||||
end
|
||||
rescue Encoding::CompatibilityError
|
||||
if raise_encoding_err
|
||||
raise
|
||||
else
|
||||
rescue Encoding::CompatibilityError
|
||||
raise if raise_encoding_err
|
||||
|
||||
encoding_diags = +"internal encoding #{Encoding.default_internal}, external encoding #{Encoding.default_external}"
|
||||
|
||||
if encoding != Encoding::UTF_8
|
||||
encoding_diags << " my encoding is #{encoding} "
|
||||
|
||||
self.force_encoding("UTF-8")
|
||||
force_encoding("UTF-8")
|
||||
unless valid_encoding?
|
||||
encode!("utf-16", "utf-8", invalid: :replace)
|
||||
encode!("utf-8", "utf-16")
|
||||
end
|
||||
Rails.logger.warn("Encountered a non UTF-8 string in SafeBuffer - #{self} - #{encoding_diags}")
|
||||
end
|
||||
|
||||
if value.encoding != Encoding::UTF_8
|
||||
|
||||
encoding_diags << " attempted to append encoding #{value.encoding} "
|
||||
|
||||
value = value.dup.force_encoding("UTF-8").scrub
|
||||
Rails.logger.warn("Attempted to concat a non UTF-8 string in SafeBuffer - #{value} - #{encoding_diags}")
|
||||
end
|
||||
|
||||
concat(value, _raise = true)
|
||||
end
|
||||
end
|
||||
|
||||
alias << concat
|
||||
ActiveSupport::SafeBuffer.prepend(self)
|
||||
ActiveSupport::SafeBuffer.class_eval("alias << concat")
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user