Sha256: 55093cbf698e43a4425cd2f8fa8ae6327b586b1fca59085f7accc627be44be46

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Mixins
    #
    # False positive mixins
    #
    module FalsePositive
      prepend MemoWise

      #
      # Normalize a falsepositive value
      #
      # @param [String] value
      #
      # @return [String, Regexp]
      #
      def normalize_falsepositive(value)
        return value if !value.start_with?("/") || !value.end_with?("/")

        # if a value is surrounded by slashes, take it as a regexp
        value_without_slashes = value[1..-2]
        Regexp.compile value_without_slashes.to_s
      end
      memo_wise :normalize_falsepositive

      #
      # Check whether a value is valid format as a disallowed data value
      #
      # @param [String] value Data value
      #
      # @return [Boolean] true if it is valid, otherwise false
      #
      def valid_falsepositive?(value)
        begin
          normalize_falsepositive value
        rescue RegexpError
          return false
        end
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mihari-6.3.0 lib/mihari/mixins/falsepositive.rb
mihari-6.2.0 lib/mihari/mixins/falsepositive.rb
mihari-6.1.0 lib/mihari/mixins/falsepositive.rb