Sha256: af8f36c2005f9959ab2e82d8f0f57ef15defea2fc3073cbc9a6b0f35a171eaf7

Contents?: true

Size: 986 Bytes

Versions: 15

Compression:

Stored size: 986 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Mixins
    module FalsePositive
      include Memist::Memoizable

      #
      # 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
      memoize :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

15 entries across 15 versions & 1 rubygems

Version Path
mihari-5.6.2 lib/mihari/mixins/falsepositive.rb
mihari-5.6.1 lib/mihari/mixins/falsepositive.rb
mihari-5.6.0 lib/mihari/mixins/falsepositive.rb
mihari-5.5.0 lib/mihari/mixins/falsepositive.rb
mihari-5.4.9 lib/mihari/mixins/falsepositive.rb
mihari-5.4.8 lib/mihari/mixins/falsepositive.rb
mihari-5.4.7 lib/mihari/mixins/falsepositive.rb
mihari-5.4.6 lib/mihari/mixins/falsepositive.rb
mihari-5.4.5 lib/mihari/mixins/falsepositive.rb
mihari-5.4.4 lib/mihari/mixins/falsepositive.rb
mihari-5.4.3 lib/mihari/mixins/falsepositive.rb
mihari-5.4.2 lib/mihari/mixins/falsepositive.rb
mihari-5.4.1 lib/mihari/mixins/falsepositive.rb
mihari-5.4.0 lib/mihari/mixins/falsepositive.rb
mihari-5.3.2 lib/mihari/mixins/falsepositive.rb