Class: Contrast::Extension::Assess::RegexpPropagator

Inherits:
Object
  • Object
show all
Includes:
Components::Interface
Defined in:
lib/contrast/extension/assess/regexp.rb,
ext/cs__assess_regexp/cs__assess_regexp.c

Overview

This Class provides us with a way to invoke Regexp propagation for those methods which are too complex to fit into one of the standard Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the Regexp Class or exposing our methods there.

Class Method Summary collapse

Methods included from Components::Interface

included

Class Method Details

.instrument_regexp_trackObject



72
73
74
75
76
77
78
79
80
# File 'lib/contrast/extension/assess/regexp.rb', line 72

def instrument_regexp_track
  @_instrument_regexp_track ||= begin
    require 'cs__assess_regexp/cs__assess_regexp'
    true
  end
rescue StandardError, LoadError => e
  logger.error('Error loading regexp track patch', e)
  false
end

.track_equal_squiggle(info_hash) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/contrast/extension/assess/regexp.rb', line 36

def track_equal_squiggle info_hash
  return unless ASSESS.enabled?

  # Because we have a special case for this propagation,
  # it falls out of regular scoping. As such, any patch to the `=~` method
  # that goes through normal channels, like that for the redos rule,
  # will force this to be in a scope of 1 (instead of the normal 0).
  # As such, a scope of 1 here indicates that,
  # so we know that we're in the top level call for this method.
  # normal patch [-alias-]> special case patch [-alias-]> original method
  # TODO: RUBY-686
  return if scope_for_current_ec.instance_variable_get(:@contrast_scope) > 1

  target = info_hash[:back_ref]
  with_contrast_scope do
    result = info_hash[:result]
    return unless result

    string = info_hash[:string]
    return unless string

    properties = Contrast::Agent::Assess::Tracker.properties(target)
    return unless properties

    properties.splat_from(string, target)
    properties.build_event(
        REGEXP_EQUAL_SQUIGGLE_NODE,
        target,
        self,
        result,
        [string])
  end
rescue Exception => e # rubocop:disable Lint/RescueException
  logger.error('Unable to propagate during Regexp#=~', e)
end