Class: SafePathValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- SafePathValidator
- Defined in:
- app/validators/safe_path_validator.rb
Constant Summary collapse
- UNSAFE =
[ nil, "bin", "boot", "dev", "etc", "lib", "lost", "proc", "root", "run", "sbin", "selinux", "srv", "usr" ]
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
19 20 21 22 23 24 |
# File 'app/validators/safe_path_validator.rb', line 19 def validate_each(record, attribute, value) return if value.nil? start = Pathname.new(value).each_filename.to_a.first # i18n-tasks-use t("activerecord.errors.models.library.attributes.path.unsafe") record.errors.add attribute, :unsafe if UNSAFE.any?(start) end |