From: Artur Molchanov Date: Thu, 3 Oct 2019 21:09:13 +0000 (+0300) Subject: Fix parsing iptables rules with hyphen in comments X-Git-Tag: v2.2.0~16^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2cee73f190c27ff7d4c14cc7afbd02bbc73e8b5a;p=puppet-modules%2Fpuppetlabs-firewall.git Fix parsing iptables rules with hyphen in comments Fix parsing rules which have comments including a hyphen mark and no space character. Example: 101-a-b-c. --- diff --git a/lib/puppet/provider/firewall/iptables.rb b/lib/puppet/provider/firewall/iptables.rb index 3bccc71..3819060 100644 --- a/lib/puppet/provider/firewall/iptables.rb +++ b/lib/puppet/provider/firewall/iptables.rb @@ -419,7 +419,7 @@ Puppet::Type.type(:firewall).provide :iptables, parent: Puppet::Provider::Firewa if values =~ %r{-m comment --comment} ind = values.index('-m comment --comment') comments = values.scan(%r{-m comment --comment "((?:\\"|[^"])*)"}) - comments += values.scan(%r{-m comment --comment ([^"]+?)\b}) + comments += values.scan(%r{-m comment --comment ([^"\s]+)\b}) values = values.gsub(%r{-m comment --comment (".*?[^\\"]"|[^ ].*)( |$)}, '') values = values.gsub(%r{-m comment --comment ([^"].*?)[ $]}, '') values.insert(ind, "-m comment --comment \"#{comments.join(';')}\" ") diff --git a/spec/fixtures/iptables/conversion_hash.rb b/spec/fixtures/iptables/conversion_hash.rb index 62d4db8..b99db65 100644 --- a/spec/fixtures/iptables/conversion_hash.rb +++ b/spec/fixtures/iptables/conversion_hash.rb @@ -254,6 +254,13 @@ ARGS_TO_HASH = { name: '9000 comment_without_quotes', }, }, + 'comments_without_quotes' => { + line: '-A INPUT -s 192.168.0.1/32 -m comment --comment 100-comment_without-quotes', + table: 'filter', + params: { + name: '100-comment_without-quotes', + }, + }, 'string_escape_sequences' => { line: '-A INPUT -m comment --comment "000 parse escaped \\"s, \\"s, \\\'s, \\\'s, \\\\s and \\\\s"', table: 'filter',