Class: Contrast::Agent::Assess::Policy::Propagator::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent/assess/policy/propagator/select.rb

Overview

This class is specifically for String#select 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 Method Summary collapse

Class Method Details

.select_tagger(patcher, preshift, ret, _block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/contrast/agent/assess/policy/propagator/select.rb', line 16

def select_tagger patcher, preshift, ret, _block
  properties = Contrast::Agent::Assess::Tracker.properties(ret)
  return unless properties

  source = preshift.object
  args = preshift.args

  # 'gotcha'
  # Additionally, an empty string is returned when the starting index for
  # a character range is at the end of the string. Let's just skip that
  # and only track a string that has length
  unless ret &&
        !ret.empty? &&
        Contrast::Agent::Assess::Tracker.tracked?(source)

    return
  end

  source_properties = Contrast::Agent::Assess::Tracker.properties(source)
  properties.build_event(
      patcher,
      ret,
      source,
      ret,
      args)

  range = determine_select_range(source, args)
  return unless range

  tags = source_properties.tags_at_range(range)
  properties.clear_tags
  tags.each_pair do |key, value|
    properties.set_tags(key, value)
  end
  ret
end