Remove NULL byte before saving strings
This commit is contained in:
@ -4,6 +4,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
|
|
||||||
before_validation :strip_strings
|
before_validation :strip_strings
|
||||||
|
before_validation :remove_null_bytes
|
||||||
|
|
||||||
def strip_strings
|
def strip_strings
|
||||||
# trim whitespace from beginning and end of string attributes
|
# trim whitespace from beginning and end of string attributes
|
||||||
@ -16,6 +17,15 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
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)
|
def self.ransackable_associations(_auth_object = nil)
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user