Class: TaintedLove::Replacer::ReplaceString

Inherits:
Base
  • Object
show all
Defined in:
lib/tainted_love/replacer/replace_string.rb

Constant Summary collapse

WRAP_METHODS =
[
  :+, :*, :[], :[]= , :replace, :strip, :strip!, :inspect
]

Instance Method Summary collapse

Methods inherited from Base

replacers, #should_replace?

Instance Method Details

#replace!Object



8
9
10
11
12
13
14
15
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
# File 'lib/tainted_love/replacer/replace_string.rb', line 8

def replace!
  mod = Module.new do
    def self.wrap_call(name)
      define_method(name) do |*args, &block|
        return super(*args, &block) unless tainted? || args.any?(&:tainted?)

        result = super(*args, &block)

        result.tainted_love_tags += tainted_love_tags if tainted?

        args.select(&:tainted?).each do |arg|
          result.tainted_love_tags += arg.tainted_love_tags
        end

        result
      end
    end

    WRAP_METHODS.each do |sym|
      wrap_call(sym)
    end

    def split(*args)
      result = super(*args)

      if tainted?
        result.each do |value|
          value.taint.tainted_love_tags += tainted_love_tags
        end
      end

      result
    end
  end

  String.prepend(mod)
end