debian-mirror-gitlab/app/validators/public_url_validator.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
777 B
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
# PublicUrlValidator
#
2019-07-31 22:56:46 +05:30
# Custom validator for URLs. This validator works like AddressableUrlValidator but
2018-11-08 19:23:39 +05:30
# it blocks by default urls pointing to localhost or the local network.
#
# This validator accepts the same params UrlValidator does.
#
# Example:
#
# class User < ActiveRecord::Base
# validates :personal_url, public_url: true
#
2019-07-31 22:56:46 +05:30
# validates :ftp_url, public_url: { schemes: %w(ftp) }
2018-11-08 19:23:39 +05:30
#
# validates :git_url, public_url: { allow_localhost: true, allow_local_network: true}
# end
#
2019-07-31 22:56:46 +05:30
class PublicUrlValidator < AddressableUrlValidator
DEFAULT_OPTIONS = {
allow_localhost: false,
allow_local_network: false
}.freeze
2018-11-08 19:23:39 +05:30
2019-07-31 22:56:46 +05:30
def initialize(options)
options.reverse_merge!(DEFAULT_OPTIONS)
super(options)
2018-11-08 19:23:39 +05:30
end
end