# frozen_string_literal: true

class UrlValidator < ActiveModel::EachValidator
  # The URL validation rules are somewhat overly strict, but should serve;
  # the idea is to prevent attackers from inserting redirecting URLs
  # that can sometimes be used to attack (e.g., "?...", or ones with <).
  URL_REGEX =
    %r{\A(|https?:\/\/[A-Za-z0-9][-A-Za-z0-9_.\/]*(\/[-A-Za-z0-9_.\/\+,#]*)?)\z}
  URL_MESSAGE = 'must begin with http: or https: and use a limited' \
                ' charset'.freeze

  def validate_each(record, attribute, value)
    return if value =~ URL_REGEX
    record.errors.add attribute, (options[:message] || URL_MESSAGE)
  end
end

class UrlValidator < ActiveModel::EachValidator
  # The URL validation rules are somewhat overly strict, but should serve;
  # the idea is to prevent attackers from inserting redirecting URLs
  # that can sometimes be used to attack (e.g., "?...", or ones with <).
  URL_REGEX =
    %r{\A(|https?:\/\/[A-Za-z0-9][-A-Za-z0-9_.\/]*(\/[-A-Za-z0-9_.\/\+,#]*)?)\z}
  URL_MESSAGE = 'must begin with http: or https: and use a limited' \
                ' charset'.freeze

  def validate_each(record, attribute, value)
    return if value =~ URL_REGEX
    record.errors.add attribute, (options[:message] || URL_MESSAGE)
  end
end

Remove redundant freeze (required by CircleCI)
Remove redundant freeze (required by CircleCI)

Signed-off-by: David A. Wheeler <9ae72d22d8b894b865a7a496af4fab6320e6abb2@dwheeler.com>
