Remove NULL byte before saving strings

This commit is contained in:
Sebastian Serth
2022-08-24 12:41:49 +02:00
parent ebf00eb475
commit 309956e472

View File

@ -4,6 +4,7 @@ class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
before_validation :strip_strings
before_validation :remove_null_bytes
def strip_strings
# trim whitespace from beginning and end of string attributes
@ -16,6 +17,15 @@ class ApplicationRecord < ActiveRecord::Base
end
end
def remove_null_bytes
# remove null bytes from string attributes
attribute_names.each do |name|
if send(name.to_sym).respond_to?(:tr)
send("#{name}=".to_sym, send(name).tr("\0", ''))
end
end
end
def self.ransackable_associations(_auth_object = nil)
[]
end