Skip to content

Commit

Permalink
fix #711 Object#=~ is called on TrueClass
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz committed Oct 14, 2022
1 parent a35381c commit 4d8fe0d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/puppet_x/icinga2/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ def self.attribute_types(attr)
end

def self.parse(row)
row = row.to_s
result = ''

# parser is disabled
if row =~ %r{^-:(.*)$}m
return Regexp.last_match(1)
end

if row =~ %r{^\{{2}(.+)\}{2}$}m
# scan function
result += '{{%{expr}}}' % { expr: Regexp.last_match(1) }
Expand Down Expand Up @@ -275,7 +276,7 @@ def self.process_hash(attrs, indent = 2, level = 3, prefix = ' ' * indent)
end
else
# String: attr = '+ value' -> attr += 'value'
if value =~ %r{^([\+,-])\s+}
if value.to_s =~ %r{^([\+,-])\s+}
operator = "#{Regexp.last_match(1)}="
value = value.sub(%r{^[\+,-]\s+}, '')
else
Expand Down Expand Up @@ -348,7 +349,7 @@ def self.attributes(attrs, globals, consts, indent = 2)
elsif value.is_a?(Array)
op = value.delete_at(0) if value[0] == '+' || value[0] == '-'
"%{ind}%{att} #{op}= [ %{lst}]\n" % { ind: ' ' * indent, att: attr, lst: process_array(value) }
elsif value =~ %r{^([\+,-])\s+}
elsif value.to_s =~ %r{^([\+,-])\s+}
# String: attr = '+ config' -> attr += config
"%{ind}%{att} #{Regexp.last_match(1)}= %{expr}\n" % { ind: ' ' * indent, att: attr, expr: parse(value.sub(%r{^[\+,-]\s+}, '')) }
else
Expand Down

1 comment on commit 4d8fe0d

@ekohl
Copy link
Member

@ekohl ekohl commented on 4d8fe0d Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think calling .to_s is wrong, since you'll just attempt to parse the literal string "true" or "false". Prior to this patch true =~ $r{} returned nil, so never matched. So a compatible change would be to return early.

Please sign in to comment.