Skip to content

Commit

Permalink
Update XML::Builder to safely handle exceptions raised in blocks
Browse files Browse the repository at this point in the history
Co-authored-by: Joana Tavares <jtavares@salsify.com>
  • Loading branch information
ric2b and rinthedev committed Nov 19, 2021
1 parent 210ecbc commit f61dc0d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/nokogiri/xml/builder.rb
Expand Up @@ -425,15 +425,18 @@ def method_missing(method, *args, &block) # :nodoc:
def insert(node, &block)
node = @parent.add_child(node)
if block
old_parent = @parent
@parent = node
@arity ||= block.arity
if @arity <= 0
instance_eval(&block)
else
yield(self)
begin
old_parent = @parent
@parent = node
@arity ||= block.arity
if @arity <= 0
instance_eval(&block)
else
yield(self)
end
ensure
@parent = old_parent
end
@parent = old_parent
end
NodeBuilder.new(node, self)
end
Expand Down

0 comments on commit f61dc0d

Please sign in to comment.