openstreetmap-website/app/validators/invalid_chars_validator.rb

9 lines
No EOL
311 B
Ruby

class InvalidCharsValidator < ActiveModel::EachValidator
INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
def validate_each(record, attribute, value)
if value =~ /[#{INVALID_CHARS}]/
record.errors[attribute] << (options[:message] || "contains invalid chars")
end
end
end