Sha256: 67af40183a6eb493db796b7d5d4cadac2c90be5a6b6d5c2017076026ae427153

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'
require 'contrast/utils/duck_utils'
require 'contrast/utils/substitution_utils'

module Contrast
  module Agent
    module Assess
      module Policy
        module Propagator
          # This class is specifically for String#(g)sub propagation
          #
          # Disclaimer: there may be a better way, but we're
          # in a 'get it work' state. hopefully, we'll be in
          # a 'get it right' state soon.
          class Substitution
            include Contrast::Components::Logger::InstanceMethods
            extend Contrast::Components::Logger::InstanceMethods
            extend Contrast::Utils::SubstitutionUtils

            class << self
              # gsub is hard. there are four versions of this method
              # 1) pattern, replacement (my fav)
              # 2) pattern, hash        (not bad)
              # 3) pattern, block       (are you kidding me?)
              # 4) pattern              (plz no)
              #
              # In addition, it requires things from $~ & $1-9, which
              # are method scoped. Rather than fight that, we'll
              # call gsub from C land using a CUSTOM patch.
              def gsub_tagger patcher, preshift, ret, block
                substitution_tagger(patcher, preshift, ret, !block.nil?)
              end

              def sub_tagger patcher, preshift, ret, block
                substitution_tagger(patcher, preshift, ret, !block.nil?, false)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-4.14.1 lib/contrast/agent/assess/policy/propagator/substitution.rb
contrast-agent-4.14.0 lib/contrast/agent/assess/policy/propagator/substitution.rb