lib/contrast/agent/assess/policy/propagator/append.rb in contrast-agent-4.3.2 vs lib/contrast/agent/assess/policy/propagator/append.rb in contrast-agent-4.4.0

- old
+ new

@@ -27,26 +27,41 @@ # if the object and the return are the same length just copy the tags # from the object(since nothing from args was added to return) if source1.length == target.length properties.copy_from(source1, target, 0, propagation_node.untags) else - # find original in the target, copy tags to the new position in - # target - original_start_index = target.index(source1) - properties.copy_from(source1, target, original_start_index, propagation_node.untags) + handle_append(propagation_node, source1, source2, target, properties) + end + properties.cleanup_tags + end - start = original_start_index + source1.length - while start < target.length - properties.copy_from(source2, target, start, propagation_node.untags) - start += source2.length - next unless start > target.length + private - properties.tags_at(start - source2.length).each do |tag| - tag.update_end(target.length) - end + # Given the append operation on source 1 added source 2 to it, changing the target output, modify the + # tags on the target to account for the change. + # + # @param propagation_node [Contrast::Agent::Assess::Policy::PropagationNode] the node responsible for the + # propagation action required by this method + # @param source1 [Object] the thing being appended to + # @param source2 [Object] the thing being appended + # @param target [Object] the result of the append operation + # @param properties [Contrast::Agent::Assess::Properties] the properties of the target + def handle_append propagation_node, source1, source2, target, properties + # find original in the target, copy tags to the new position in + # target + original_start_index = target.index(source1) + properties.copy_from(source1, target, original_start_index, propagation_node.untags) + + start = original_start_index + source1.length + while start < target.length + properties.copy_from(source2, target, start, propagation_node.untags) + start += source2.length + next unless start > target.length + + properties.tags_at(start - source2.length).each do |tag| + tag.update_end(target.length) end end - properties.cleanup_tags end end end end end